3、常见三种配置方式:XML、Annotation、JavaConfig([color=red]spring3.0新增[/color])
JavaConfig配置:
下面有service、dao层的配置:
更详细javaConfig见spring文档
JavaConfig配置:
@Configuration
public class AppConfig {
@Bean
public UserDAO userDAO() {
return new UserDAOImpl();
}
//xml
//<bean id = "userDAO" class="userDAO()"
}
下面有service、dao层的配置:
@Configuration
public class AppConfig {
@Bean
public UserDAO userDAO() {
return new UserDAOImpl();
}
@Bean
public UserService userService() {
UserServiceImpl service = new UserServiceImpl();
service.setUserDAO(userDAO());
return service;
}
}
更详细javaConfig见spring文档