监听器中spring注入相关的问题
<listener>
<listener-class>com.cairh.xpe.aips.web.Test.TestLinstener</listener-class>
</listener>
2、写监听器实现ServletContextListener并重写相应的方法
public class TestLinstener implements ServletContextListener{
@Autowired
MessMediaService messMediaService;
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("*************执行相关方法************");
//spring容器中获取service对象
MessMediaService service = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(MessMediaService.class);
service.test();
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
}
}
3、service类
@Lazy(false)
@Service
public class MessMediaService { @Autowired
private ITaskService taskService; private RedisLock redisLock = new RedisLock(); private Map taskMap = (Map)JSON.parse(RedisClientUtil.get("config.cache./aips/tasksettings.properties")); private Thread thread = new Thread(new Runnable() { @Override
public void run() { }
}); public int test(){
taskService.test();
...
return 1;
} public MessMediaService() {
super();
System.out.println("*******************测试构造方法********************");
} @PostConstruct
private void init() throws Exception {
System.out.println("*******************init******************");
thread.start();
} }
解决历程:
监听器中spring注入相关的问题的更多相关文章
- 项目中Spring注入报错小结
之前在做单元测试时采用注解方式进行service对象的注入,但运行测试用例时对象要注入的service对象总是空的,检查下spring配置文件,我要配置的bean类xml文件已经包含到spring要加 ...
- xfire发布的Webservice中Spring注入为空的解决方案
Spring框架使用中注入为空是一个比较头疼的问题,遇到Webservice和Spring框架配合时,这个问题更容易出现并很难发现问题的原因. 在做SSO系统中就遇到这样的问题,在Service的实现 ...
- spring注入相关注解
本次主要整理四个注解 @ComponentScan.@Scope.@Conditional.@Import 1. @ComponentScan(value = "com.xiaoguo&qu ...
- java 从spring容器中获取注入的bean对象
java 从spring容器中获取注入的bean对象 CreateTime--2018年6月1日10点22分 Author:Marydon 1.使用场景 控制层调用业务层时,控制层需要拿到业务层在 ...
- JSP中使用Spring注入的Bean时需要注意的地方
遇到问题 遇到一个问题:在JSP中,使用Spring注入的Bean对象时,未能正确地获取到想要的对象. 郁闷的是,它也没报错. 研究问题 使用DEBUG功能(好久不在JSP里写Java代码了,都忘了J ...
- Spring中的注入方式 和使用的注解 详解
注解:http://www.cnblogs.com/liangxiaofeng/p/6390868.html 注入方式:http://www.cnblogs.com/java-class/p/4727 ...
- Spring注入中byType和byName的总结
1.首先,区分清楚什么是byType,什么是byName. <bean id="userServiceImpl" class="cn.com.bochy.servi ...
- 线程中无法实例化spring注入的服务的解决办法
问题描述 在Java Web应用中采用多线程处理数据,发现Spring注入的服务一直报NullPointerException.使用注解式的声明@Resource和XML配置的bean声明,都报空指针 ...
- boot中 Quartz注入spring管理类失败
在项目中用到了Quartz,想在里面实现业务操作发现sping类注入总是失败.后来网上查询了一下解决办法.下面把我成功解决问题的这个版本发出来,大家一起学习一下. 在quartz 会发现 job中无法 ...
随机推荐
- 05-Servlet与内部加载机制(part1)
一.什么是Servlet Servlet 运行在服务端的Java小程序, 是sun公司提供一套规范(接口) 主要功能: 用来处理客户端请求 响应给浏览器的动态资源 servlet的实质就是j ...
- K:逆波兰算法
相关介绍: 一种求解字符串形式的表达式的结果的算法,该算法在求解时,需要先将我们平日里习惯上使用的中序表达式的模式转化为等价的后序(后缀)表达式的模式,之后再通过求解出该后序(后缀)表达式的结果而得 ...
- js实现栈结构
实现栈结构 //创建栈 function Stack (){ let items = [] this.push = function(element){ items.push(element) } t ...
- THUSC2018退役预定
Day-inf \(HNOI,CTSC,APIO\)都爆炸了之后 好不容易找回自信心,怀着一定报不上的心情报了清华 居然报上了怕不是报了的都通过了 毕竟\(wc\)的时候被清华虐惨了 还是很虚的 Da ...
- [算法练习]String to Integer (atoi)
题目说明: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ...
- [算法练习]Reverse Integer
题目说明: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321 ...
- Bootstrap 在线引用
Bootstrap 3.3.0 js 文件 <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.j ...
- EventTarge Node Docuement Element HTMLElement 关系
综述: 可以将其看做是依次继承的关系: Node Node A Node is an interface from which a number of DOM types inherit, and a ...
- mongodb shell警告
# mongoMongoDB shell version: 3.0.2connecting to: testServer has startup warnings: 2015-05-09T12:34: ...
- c# 调用 c dll 例子
// case 1 传递 int* ///////////////////////////////////////////// extern “C” __declspec(dllexport) int ...