问题描述
Error creating bean with name 'sqlMapClient' defined in ServletContext resource [/WEB-INF/config/common/applicationContext.xml]: Unsatisfied dependency expressed through bean property 'configLocation':Cannot find class [com.neusoft.gmsbs.gms.user.dao.impl.UserDAOImpl] for bean with name 'userDAO' defined in ServletContext resource [/WEB-INF/config/gms/user/applicationContext_user.xml]; nested exception is java.lang.ClassNotFoundException: 以上是错误信息提示,我在applicationContext_user.xml中的配置是<?xml version="1.0" encoding="UTF-8"?><beans default-autowire="autodetect" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> <bean id="userAction" class="com.neusoft.gmsbs.gms.user.action.UserAction" scope="prototype"> <property name="userBO" ref="userBO" /> </bean> <bean id="userBO" class="com.neusoft.gmsbs.gms.user.bo.impl.UserBOImpl"> <property name="userDAO" ref="userDAO" /> </bean> <bean id="userDAO" class="com.neusoft.gmsbs.gms.user.dao.impl.UserDAOImpl"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean></beans>路径都没错,我检查了N遍,这个问题让我研究了2天了,请求高手给我解脱! 问题补充:applicationContext.xml的代码是:<?xml version="1.0" encoding="UTF-8"?><beans default-autowire="autodetect" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:flex="http://www.springframework.org/schema/flex" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd"> <!-- 加载数据库参数的配置文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" lazy-init="default" autowire="default" dependency-check="default"> <property name="locations"> <list merge="default"> <value> WEB-INF/config/common/properties/jdbc.properties </value> </list> </property> </bean> <!-- spring整合ibatis框架 --><bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><property name="configLocations" value="WEB-INF/config/common/sqlMapConfig.xml" /><property name="dataSource" ref="dataSourceLocal" /></bean></beans>sqlMapConfig.xml的代码是:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <settings useStatementNamespaces="true"/> <sqlMap resource="../config/gms/user/sqlMap_user.xml" /> </sqlMapConfig>struts.xml的代码是:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <!-- 每个模块增加struts配置文件均需在此添加说明 --> <include file="../config/gms/user/struts_user.xml" /> <package name="common" extends="struts-default"> </package></struts>3个映射文件分别是applicationContext_user.xml sqlMap_user.xml struts_user.xml 代码按顺序来分别是<?xml version="1.0" encoding="UTF-8"?><beans default-autowire="autodetect" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> <bean id="userAction" class="com.neusoft.gmsbs.gms.user.action.UserAction" scope="prototype"> <property name="userBO" ref="userBO" /> </bean> <bean id="userBO" class="com.neusoft.gmsbs.gms.user.bo.impl.UserBOImpl"> <property name="userDAO" ref="userDAO" /> </bean> <bean id="userDAO" class="com.neusoft.gmsbs.gms.user.dao.impl.UserDAOImpl"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean></beans>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMapPUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN""http://www.ibatis.com/dtd/sql-map-2.dtd"><sqlMap namespace="user"></sqlMap>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="user" extends="common"> </package></struts>求解脱
解决方案
No bean named 'dataSource' is defined 这里不是显示没有定义dataSource吗?
解决方案二:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.web.core.conn.SQLManager#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.jdbc.core.JdbcTemplate com.web.core.conn.SQLManager.jdbctemplate; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.web.sch.action.QueryAction] for bean with name 'queryAction' defined in file [D:Tomcat 7.0webappsxjcwebWEB-INFclassesspringapplicationContext-datasource.xml]; nested exception is java.lang.ClassNotFoundException: com.web.sch.action.QueryActionat org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:574)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1114)at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1673)at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)at java.util.concurrent.FutureTask.run(FutureTask.java:166)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)at java.lang.Thread.run(Thread.java:722)Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.jdbc.core.JdbcTemplate com.web.core.conn.SQLManager.jdbctemplate; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.web.sch.action.QueryAction] for bean with name 'queryAction' defined in file [D:Tomcat 7.0webappsxjcwebWEB-INFclassesspringapplicationContext-datasource.xml]; nested exception is java.lang.ClassNotFoundException: com.web.sch.action.QueryActionat org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
解决方案三:
我说的是异常信息
解决方案四:
你把错误的代码贴全一些吧,感觉还有一部分没有显示
解决方案五:
你把代码传上来吧,依赖的jar就不需要了,只要源代码
解决方案六:
楼主是东软的哈,sqlMapClient这个依赖的bean不能实例化。Unsatisfied dependency expressed through bean property 'configLocation': 提示的很清楚呀。。没有注入这个bean:sqlMapClient