spring mvc 初始化加载bean

<context:component-scan base-package="com.hiway.entity"></context:component-scan>
	
	<bean name="service" class="com.hiway.entity.UserService" scope="prototype">
	
	</bean>
@Component("service")
public class UserService {

	private User u ;

	public User getU() {
		return u;
	}

	@Resource(name="u")
	public void setU(User u) {
		this.u = u;
	}
	
	@PostConstruct
	public void init(){
		System.out.println("post constructor");
	}
	
	@PreDestroy
	public void destroy(){
		System.out.println("pre destroy");
	}
}

猜你喜欢

转载自hoochiang.iteye.com/blog/2305323