-
day61 - Spring Framework(스프링, DI)KIC/Spring 2021. 9. 10. 00:11반응형
[Container3.xml]
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="user1" class="di03.User"> <constructor-arg value="bkchoi" /> <constructor-arg value="1234" /> </bean> <bean id="user2" class="di03.User"> <constructor-arg value="madvirus" /> <constructor-arg value="qwer" /> </bean> <bean id="userRepository" class="di03.UserRepository"> <property name="users"> <list> <ref bean="user1" /> <ref bean="user2" /> </list> </property> </bean> <bean id="pwChangeSvc" class="di03.PasswordChangeService"> <constructor-arg><ref bean="userRepository"/></constructor-arg> </bean> <bean id="authFailLogger" class="di03.AuthFailLogger"> <property name="threshold" value="2"/> </bean> <bean id="authenticationService" class="di03.AuthenticationService"> <property name="failLogger" ref="authFailLogger"/> <property name="userRepository" ref="userRepsitory" /> </bean> </beans>
[user.java]
package di03; public class User { private String id; private String password; public User(String id, String password) { super(); this.id = id; this.password = password; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } package di03; public class User { private String id; private String password; public User(String id, String password) { super(); this.id = id; this.password = password; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } package di03; public class User { private String id; private String password; public User(String id, String password) { super(); this.id = id; this.password = password; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
[UserRepository.java]
package di03; import java.util.HashMap; import java.util.List; import java.util.Map; public class UserRepository { private Map<String, User> userMap = new HashMap<String, User>(); public void setUsers(List<User> users) { for(User u : users) { userMap.put(u.getId(), u); } } }
[AuthFailLogger.java]
package di03; public class AuthFailLogger { private int threshold; public void setThreshold(int threshold) { this.threshold = threshold; } }
[AuthenticationService.java]
package di03; public class AuthenticationService { AuthFailLogger authFailLogger; UserRepository userRepository; public void setFailLogger(AuthFailLogger authFailLogger) { this.authFailLogger = authFailLogger; } public void setUserRepository(UserRepository userRepository) { this.userRepository = userRepository; } }
300x250'KIC > Spring' 카테고리의 다른 글
day65 - Spring Framework(스프링, Annotation) (0) 2021.09.15 day64 - Spring Framework(스프링, AOP) (0) 2021.09.14 day63 - Spring Framework(스프링, AOP) (0) 2021.09.13 day62 - Spring Framework(스프링, Annotation) (0) 2021.09.10 day60 - Spring Framework(스프링, DI 시작) (0) 2021.09.08