码迷,mamicode.com
首页 > 编程语言 > 详细

spring postconstruct

时间:2016-05-15 21:23:49      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:

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容器初始化之后,如果需要加载数据,可以这么做。。。

spring postconstruct

标签:

原文地址:http://www.cnblogs.com/sdnu/p/5495959.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!