问题描述
在web.xml中新增Filter后,Tomcat启动失败。报错信息见后文。
原因分析
在新增的Filter中,通过注解使用Spring的Bean来处理数据:
@Resource
MyService myService;
通过注解获取Service对象失败,导致Filter初始化失败,启动报错。
解决方法
在Filter中获取Bean时,改为从ApplicationContext获取,而不使用注解。
String myString = WebApplicationContextUtils.getWebApplicationContex(request.getServletContext()).getBean(MyService.class).xxxMethod(myParams);
报错信息
Server栏报错:
org.apache.catalina.loader.WebappClassLoaderBase loadClass
信息: Illegal access: this web application instance has been stopped already. Could not load org.springframework.core.NestedExceptionUtils. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1813)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1771)
at org.springframework.core.NestedRuntimeException.<clinit>(NestedRuntimeException.java:45)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:289)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:37)
at org.activiti.engine.im