@Configuration
public class MemberConfig {
//<bean id="studentDao" class="ems.member.dao.StudentDao" ></bean>
@Bean
public StudentDao studentDao() {
return new StudentDao();
}
/*
<bean id="registerService" class="ems.member.service.StudentRegisterService">
<constructor-arg ref="studentDao" ></constructor-arg>
</bean>
*/
@Bean
public StudentModifyService registerService() {
return new StudentModifyService(studentDao());
}
@Bean
public StudentRegisterService modifyService() {
return new StudentRegisterService(studentDao());
}
@Bean
public StudentDeleteService deleteService() {
return new StudentDeleteService(studentDao());
}
@Bean
public StudentSelectService selectService() {
return new StudentSelectService(studentDao());
}
@Bean
public StudentAllSelectService allSelectService() {
return new StudentAllSelectService(studentDao());
}
/*
<bean id="dataBaseConnectionInfoDev" class="ems.member.DataBaseConnectionInfo">
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="userId" value="scott" />
<property name="userPw" value="tiger" />
</bean>
*/
@Bean
public DataBaseConnectionInfo dataBaseConnectionInfoDev() {
DataBaseConnectionInfo dbInfoDev = new DataBaseConnectionInfo();
dbInfoDev.setJdbcUrl("jdbc:mysql://localhost/sogongdo?characterEncoding=utf8&serverTimezone=UTC&useSSL=false");
dbInfoDev.setUserId("root");
dbInfoDev.setUserPw("7452");
return dbInfoDev;
}
@Bean
public DataBaseConnectionInfo dataBaseConnectionInfoReal() {
DataBaseConnectionInfo dbInfoReal = new DataBaseConnectionInfo();
dbInfoReal.setJdbcUrl("jdbc:mysql://localhost/sogongdo?characterEncoding=utf8&serverTimezone=UTC&useSSL=false");
dbInfoReal.setUserId("masterid");
dbInfoReal.setUserPw("masterpw");
return dbInfoReal;
}
/*
<bean id="informationService" class="ems.member.service.EMSInformationService">
<property name="developers">
<list>
<value>Cheney.</value>
<value>Eloy.</value>
<value>Jasper.</value>
<value>Dillon.</value>
<value>Kian.</value>
</list>
</property>
<property name="administrators">
<map>
<entry>
<key>
<value>Cheney</value>
</key>
<value>cheney@springPjt.org</value>
</entry>
<entry>
<key>
<value>Jasper</value>
</key>
<value>jasper@springPjt.org</value>
</entry>
</map>
</property>
<property name="dbInfos">
<map>
<entry>
<key>
<value>dev</value>
</key>
<ref bean="dataBaseConnectionInfoDev"/>
</entry>
<entry>
<key>
<value>real</value>
</key>
<ref bean="dataBaseConnectionInfoReal"/>
</entry>
</map>
</property>
</bean>
*/
@Bean
public EMSInformationService informationService(){
EMSInformationService emsInfo = new EMSInformationService();
ArrayList<String> developers = new ArrayList<String>();
developers.add("Cheney");
developers.add("Eloy");
developers.add("Jasper");
developers.add("Dillon");
developers.add("Kian");
emsInfo.setDevelopers(developers);
Map<String,String> administrators = new HashMap<String,String>();
administrators.put("Cheney", "cheney@springPjt.org");
administrators.put("Jasper", "jasper@springPjt.org");
emsInfo.setAdministrators(administrators);
Map<String, DataBaseConnectionInfo> dbInfos = new HashMap<String, DataBaseConnectionInfo>();
dbInfos.put("dev", dataBaseConnectionInfoDev());
dbInfos.put("real", dataBaseConnectionInfoReal());
emsInfo.setDbInfos(dbInfos);
return emsInfo;
}
}
파일 분리시
@Configuration
public class MemberConfig3 {
@Autowired //자동주입
DataBaseConnectionInfo dataBaseConnectionInfoDev;
@Autowired
DataBaseConnectionInfo dataBaseConnectionInfoReal;
@Bean
public EMSInformationService informationService() {
Map<String, DataBaseConnectionInfo> dbInfos = new HashMap<String, DataBaseConnectionInfo>();
dbInfos.put("dev", dataBaseConnectionInfoDev);
dbInfos.put("real", dataBaseConnectionInfoReal);
info.setDbInfos(dbInfos);
return info;
}
}
<bean id="dataBaseConnectionInfoDev" class="ems.member.DataBaseConnectionInfo">
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="userId" value="scott" />
<property name="userPw" value="tiger" />
</bean>
파일분리
@Configuration
@Import({MemberConfig2.class, MemberConfig3.class})
public class MemberConfigImport {..}
메인에서 적용
AnnotationConfigApplicationContext ctx =
new AnnotationConfigApplicationContext(MemberConfig1.class, MemberConfig2.class, MemberConfig3.class);
EMSInformationService informationService = ctx.getBean("informationService", EMSInformationService.class);
informationService.outputEMSInformation();
'Back-end > Spring Framework' 카테고리의 다른 글
java spring 스프링 mvc 웹서비스 STS(spring tools suite) (0) | 2020.08.06 |
---|---|
java spring 스프링 MVC 플레임워크 설계 구조 (0) | 2020.08.04 |
java spring 스프링 설정 파일 분리 (xml), 범위 (0) | 2020.07.26 |
java spring 다양한 의존 객체 주입 (DI) , 초기메서드-destroy메서드 (0) | 2020.07.24 |
java spring 프로젝트 생성과 실행 기초 (0) | 2020.07.21 |
댓글