BAEL-833: How to get last element of a Stream in Java? (#1930)
* Different Types of Bean Injection in Spring * Fixed code formatting and test names for "Different Types of Bean Injection in Spring" * BAEL-833: How to get last element of a Stream in Java? * BAEL-833: Updated based on review from editor
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
99c7a91587
commit
8c8c01ebbb
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.beaninjection;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FileReader {
|
||||
|
||||
@Autowired
|
||||
private Location location;
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.beaninjection;
|
||||
|
||||
public class FtpReader {
|
||||
private String ftpHost = null;
|
||||
private Integer ftpPort = null;
|
||||
|
||||
// Constructor with arguments
|
||||
public FtpReader(String host, Integer port) {
|
||||
this.ftpHost = host;
|
||||
this.ftpPort = port;
|
||||
}
|
||||
|
||||
public String getFtpHost() {
|
||||
return ftpHost;
|
||||
}
|
||||
|
||||
public void setFtpHost(String ftpHost) {
|
||||
this.ftpHost = ftpHost;
|
||||
}
|
||||
|
||||
public Integer getFtpPort() {
|
||||
return ftpPort;
|
||||
}
|
||||
|
||||
public void setFtpPort(Integer ftpPort) {
|
||||
this.ftpPort = ftpPort;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.beaninjection;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Location {
|
||||
private String filePath;
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.beaninjection;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = { "com.baeldung.beaninjection" })
|
||||
public class ReaderApplicationConfig {
|
||||
|
||||
@Bean
|
||||
public FtpReader exampleDAO() {
|
||||
return new FtpReader("localhost", 21);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.beaninjection;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ReaderManager {
|
||||
private FileReader fileReader;
|
||||
private FtpReader ftpReader;
|
||||
|
||||
@Autowired
|
||||
public ReaderManager(FtpReader ftpReader) {
|
||||
this.ftpReader = ftpReader;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setFileReader(FileReader fileReader) {
|
||||
this.fileReader = fileReader;
|
||||
}
|
||||
|
||||
public FileReader getFileReader() {
|
||||
return fileReader;
|
||||
}
|
||||
|
||||
public void setFtpReader(FtpReader ftpReader) {
|
||||
this.ftpReader = ftpReader;
|
||||
}
|
||||
|
||||
public FtpReader getFtpReader() {
|
||||
return ftpReader;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.beaninjection;
|
||||
|
||||
public class ReaderService {
|
||||
private FtpReader ftpReader;
|
||||
|
||||
public void setFtpReader(FtpReader reader) {
|
||||
this.ftpReader = reader;
|
||||
}
|
||||
|
||||
public FtpReader getFtpReader() {
|
||||
return ftpReader;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean name="ftpReader" class="com.baeldung.beaninjection.FtpReader">
|
||||
<constructor-arg value="localhost" />
|
||||
<constructor-arg value="21" />
|
||||
</bean>
|
||||
|
||||
<bean name="readerService" class="com.baeldung.beaninjection.ReaderService">
|
||||
<property name="ftpReader" ref="ftpReader" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user