如何让spring在启动后立即执行我需要的操作??

如何让spring在启动后立即执行我需要的操作??
是applicationContext初始化完成后调用,并非某一个bean的初始化
[b]问题补充:[/b]
我详细说下我的需求吧,我在项目中将公用数据放入了hibernate的二级缓存,比如地区等。在spring初始化完成后我想调用下service层的查询方法,然后将结果缓存,这样项目启动后公用数据就自动加载并缓存了,搞人们都有什么看法和好的建议,我不想使用application,这样存取太麻烦,既然用了缓存就全部缓存。不知道哦我的想法对不对。
[b]问题补充:[/b]
高人打成了搞人了,高人不要见怪啊
[b]问题补充:[/b]
感谢高人们的指点,最终我选择了实现BeanFactoryPostProcessor接口,这样可以调用任何我想调用的service,因为我在调用之前这些service必须要被实例化。再次感谢各位高人

就实现一个BeanPostProcessor就能做到了,

去试看看就知道

可以举个例子不?你想进行什么操作?是一定要等applicationContext完全初始化完成吗?

要不这样吧Spring在启动完成的时候会发出一个ContextRefreshedEvent,你可以考虑用一个bean实现ApplicationListener接口,然后你判断下是ContextRefreshedEvent的时候,代表SPring已经初始完毕,然后你再进行你的操作;这样符合你的需求吗?

如果你想在Spring容器完成bean的实例化、配置和其它的初始化后执行一些自定义逻辑,你可以插入一个或多个的BeanPostProcessor实现

[code="java"]
package scripting;

import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.BeansException;

public class InstantiationTracingBeanPostProcessor implements BeanPostProcessor {

// simply return the instantiated bean as-is
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    return bean; // we could potentially return any object reference here...
}

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    System.out.println("Bean '" + beanName + "' created : " + bean.toString());
    return bean;
}

}

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd">

<!-- 
    when the above bean ('messenger') is instantiated, this custom
    BeanPostProcessor implementation will output the fact to the system console
 -->
<bean class="scripting.InstantiationTracingBeanPostProcessor"/>

[/code]

恩 如果是这样话如我第一次回答你的那样给一个bean添加一个init-method作为初始化方法,调用你的查询方法就可以了啊;不需要完全等Spring启动完毕;