问题描述
- 注解出错,这个框架接触不久,按照前人的配置方式配置后出该问题
-
11:29:59.477 ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource [/WEB-INF/config/jeecms-servlet-front.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applyAct': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.jeecms.dzpt.manager.ApplyMng com.jeecms.dzpt.action.ApplyAct.applyMng; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.jeecms.dzpt.manager.ApplyMng] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:398) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1146) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:275) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.initHandlerMappings(DispatcherServlet.java:424) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.initStrategies(DispatcherServlet.java:339) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.onRefresh(DispatcherServlet.java:328) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.onApplicationEvent(FrameworkServlet.java:523) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:749) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:1) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.event.GenericApplicationListenerAdapter.onApplicationEvent(GenericApplicationListenerAdapter.java:51) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.event.SourceFilteringListener.onApplicationEventInternal(SourceFilteringListener.java:97) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.event.SourceFilteringListener.onApplicationEvent(SourceFilteringListener.java:68) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:911) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:428) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) [spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:212) [servlet-api.jar:2.5.MR2]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1213) [catalina.jar:6.0.44]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026) [catalina.jar:6.0.44]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4425) [catalina.jar:6.0.44]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4738) [catalina.jar:6.0.44]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:802) [catalina.jar:6.0.44]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779) [catalina.jar:6.0.44]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:583) [catalina.jar:6.0.44]
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1080) [catalina.jar:6.0.44]
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1003) [catalina.jar:6.0.44]
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:507) [catalina.jar:6.0.44]
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1322) [catalina.jar:6.0.44]
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:325) [catalina.jar:6.0.44]
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142) [catalina.jar:6.0.44]
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1068) [catalina.jar:6.0.44]
at org.apache.catalina.core.StandardHost.start(StandardHost.java:822) [catalina.jar:6.0.44]
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060) [catalina.jar:6.0.44]
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) [catalina.jar:6.0.44]
at org.apache.catalina.core.StandardService.start(StandardService.java:525) [catalina.jar:6.0.44]
at org.apache.catalina.core.StandardServer.start(StandardServer.java:759) [catalina.jar:6.0.44]
at org.apache.catalina.startup.Catalina.start(Catalina.java:595) [catalina.jar:6.0.44]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_43]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_43]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_43]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_43]
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) [bootstrap.jar:6.0.44]
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) [bootstrap.jar:6.0.44]
解决方案
这个应该是springmvc吧,,看下你的配置
解决方案二:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/config/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="autoCommitOnClose" value="true"/>
<property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
<property name="initialPoolSize" value="${cpool.minPoolSize}"/>
<property name="minPoolSize" value="${cpool.minPoolSize}"/>
<property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
<property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
<property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 去除该动动就不用从jar中加载cmshibernate配置文件了 -->
<!-- <property name="mappingJarLocations">
<list>
<value>/WEB-INF/lib/zqxcom-cms.jar</value>
</list>
</property> -->
<property name="mappingLocations">
<list>
<value>classpath*:/com/jeecms/core/entity/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/main/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/assist/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/dzpt/entity/hbm/Advisory.hbm.xml</value>
<value>classpath*:/com/jeecms/dzpt/entity/hbm/Apply.hbm.xml</value>
</list>
</property>
<!-- hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect -->
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.query.substitutions=true 1, false 0
hibernate.jdbc.batch_size=20
hibernate.cache.use_query_cache=true
</value>
</property>
<property name="entityInterceptor">
<ref local="treeInterceptor"/>
</property>
<property name="cacheProvider">
<ref local="cacheProvider"/>
</property>
<property name="lobHandler">
<ref bean="lobHandler" />
</property>
</bean>
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/>
<bean id="cacheProvider" class="com.jeecms.common.hibernate3.SpringEhCacheProvider">
<property name="configLocation">
<value>classpath:ehcache-hibernate.xml</value>
</property>
<property name="diskStoreLocation">
<value>/WEB-INF/cache/hibernate</value>
</property>
</bean>
<bean id="treeInterceptor" class="com.jeecms.common.hibernate3.TreeIntercptor"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<context:annotation-config/>
<tx:annotation-driven transaction-manager="transactionManager" />
解决方案三:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/config/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="autoCommitOnClose" value="true"/>
<property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
<property name="initialPoolSize" value="${cpool.minPoolSize}"/>
<property name="minPoolSize" value="${cpool.minPoolSize}"/>
<property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
<property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
<property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 去除该动动就不用从jar中加载cmshibernate配置文件了 -->
<!-- <property name="mappingJarLocations">
<list>
<value>/WEB-INF/lib/zqxcom-cms.jar</value>
</list>
</property> -->
<property name="mappingLocations">
<list>
<value>classpath*:/com/jeecms/core/entity/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/main/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/assist/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/dzpt/entity/hbm/Advisory.hbm.xml</value>
<value>classpath*:/com/jeecms/dzpt/entity/hbm/Apply.hbm.xml</value>
</list>
</property>
<!-- hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect -->
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.query.substitutions=true 1, false 0
hibernate.jdbc.batch_size=20
hibernate.cache.use_query_cache=true
</value>
</property>
<property name="entityInterceptor">
<ref local="treeInterceptor"/>
</property>
<property name="cacheProvider">
<ref local="cacheProvider"/>
</property>
<property name="lobHandler">
<ref bean="lobHandler" />
</property>
</bean>
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/>
<bean id="cacheProvider" class="com.jeecms.common.hibernate3.SpringEhCacheProvider">
<property name="configLocation">
<value>classpath:ehcache-hibernate.xml</value>
</property>
<property name="diskStoreLocation">
<value>/WEB-INF/cache/hibernate</value>
</property>
</bean>
<bean id="treeInterceptor" class="com.jeecms.common.hibernate3.TreeIntercptor"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<context:annotation-config/>
<tx:annotation-driven transaction-manager="transactionManager" />
解决方案四:
Could not autowire field: private com.jeecms.dzpt.manager.ApplyMng com.jeecms.dzpt.action.ApplyAct.applyMng;
无法注入,是不是大小写没有对应,或者没有注入实体类
解决方案五:
@Autowire默认按照类型装配
@Resource默认按照名称装配,当找不到与名称匹配的bean才会按照类型装配。
错误是找不到匹配的bean,一种出错的原因可能是因为你没有扫描通过注解配置的javabean,或者忘记加注解,Spring容器里没有javabean对象,
如果是配合@Autowire和@Qualifier使用的话,把@Qualifier注解去掉试试。最好把代码贴出来看一下。