spring postconstruct

package com.jdw.service.impl;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service; import com.jdw.bean.User;
import com.jdw.dao.UserMapper;
import com.jdw.service.UserService; @Service("userService")
public class UserServiceImpl implements UserService { @Autowired
// 注入
private UserMapper userMapper; private List<User> users = null; public UserServiceImpl() {
super(); } @PostConstruct
private void init() {
System.out.println("start init..");
users = userMapper.selectList();
System.out.println("已经初始化users...");
} @Override
public List<User> getUsers() {
// TODO Auto-generated method stub
return users;
} }

如果spring容器初始化之后,如果需要加载数据,可以这么做。。。

上一篇:Thread+Handler 线程 消息循环(转载)


下一篇:五:MyBatis学习总结(五)——实现关联表查询