ITeye博客

spring mvc 初始化加载bean

hoochiang · 2016-06-15 20:28 · java · spring · 编程语言 · Spring · Markdown

<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");
	}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。