Spring3.0新特性(三)

3、常见三种配置方式:XML、Annotation、JavaConfig( spring3.0新增
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文档

你可能感兴趣的:(java,DAO,spring,xml,bean)