我的问题是看这个博客解决的:http://blog.csdn.net/jimbo3693/article/details/52524587
总结下我解决的方式和遇到的问题。
使用tomcat启动报错,具体报错信息如下:
严重: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'quartzJob': Unsatisfied dependency expressed through field 'appController'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean found for dependency [com.lizx.app.AppController]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean found for dependency [com.lizx.app.AppController]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1463)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1094)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1056)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566)
... 24 more
-----------------------------------------------------------------------------------------------------------------------
刚开始我把@Autowired注解掉就好了
很好奇,不加入quartz的时候,使用@Autowired一点问题都没有,可是加上后却启动报错,我开始时以为是jar包冲突,挨个检查jar包对比,没有发现少或冲突的。
同时也在我的类上加入了@Component和@Controller注解,也不能用,最后从网上看到了这篇博客:http://blog.csdn.net/jimbo3693/article/details/52524587,发现在spring中确实没有加
---------------------------------以下是引用别人博客的内容----------------------------------
突然出现此问题,让我研究了一天一夜,终于找到问题所在(Myeclipse代码编译错误导致,Project->clean 就好了)。
上述异常是控制台中报出来的,根据其意思是注入的Bean对象不存在,导致此问题的原因主要是看直接原因还是间接原因(也就这几种原因能导致此问题)。
直接原因:Bean对象的注解标签没有添加 ( 如 @Controller, @Service,@Repository等等),或者是注解的扫描是否打开,即在applicationContext.xml 上下文中是否配置了 :
光从上述异常中是无法看出注解是否启动扫描的。
间接原因:1. 代码编译问题导致。如,Myeclipse 或其他IDE工具。 这种clean 重新编译即可
2. JDK 与 Spring 版本不兼容 根据自己的JDK找相应支持的Jar
3. 缺少注解相关的Jar 文件 在网上找标准配置清单(网上一堆)
4. 扫描器配置冲突检查web.xml ,applicationContext.xml 和aplicationContext-mvc.xml中注解相关配置是否正确。
在Java Web项目中 使用SpringMVC +Hibernate+全注解的过程中,虽然减轻了Struts的XML繁重配置,但同时给接触SpringMVC注解不深的人也带来了许多问题。所有的Bean都依赖于注解的扫描注入,此过程的实现全部封装在了Spring的Jar包中,开发人员可无需关心注入的整个过程,但一旦注入出现问题,会让很多对注解了解不深的人头疼不已。看着密密麻麻的Exception,却无从下手。