求解决org.springframework.beans.factory.BeanCreationException

dwr和spring整合时出的问题,请问有谁知道这是怎么回事呢?
具体代码如下:

dwr.xml

[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">



<!-- 用户信息 -->


<!-- 组织信息 -->
match="com.tw.pojo.OrgBean">

    <!-- 用户DWR调用定义 -->
    <create creator="spring" javascript="DWRUserDao">
        <param name="beanName" value="userDao"/>
    </create>
    <!-- 组织DWR调用定义 -->
    <create creator="spring" javascript="DWROrgDao">
        <param name="beanName" value="orgDao"/>
    </create>

</allow>


[/code]

UserDaoImpl.java

[code="java"]
public List getUserListInfo(String orgid) {
Map map = new HashMap();
map.put("orgid", orgid);
try {
List list = (List) this.getSqlMapClientTemplate().queryForList(
"getUserListInfo", map);
if (list != null) {
return list;
}
} catch (Exception e) {
log.error("获取指定组织的所有直用户getUserListInfo:", e);
e.printStackTrace();
}
return null;
}

[/code]

applicationContext.xml
[code="java"]

<bean id="baseDao" class="com.tw.framework.base.db.BaseDaoOracle"
    scope="prototype">
</bean>

<!-- 用户角色信息 -->
<bean id="userDao" class="com.tw.dao.impl.UserDaoImpl" scope="prototype">
    <property name="baseDao" ref="baseDao" />
</bean>

<!-- 组织信息 -->
<bean id="orgDao" class="com.tw.dao.impl.OrgDaoImpl" scope="prototype">
    <property name="baseDao" ref="baseDao" />
</bean>

[/code]

jsp代码

[code="java"]

    <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/DWROrgDao.js'></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>    
    <script language="javascript">
    //初始化页面中各控制的值
    javascript:dwr.engine.setAsync(false);
    function loadControls()
    {
        loadSelectAreaList();
    }

    //Load所有公司信息,并将之设置到公司列表控制
    function loadSelectAreaList()
    {
        document.all.ddlArea.length = 1;
        //设置公司列表控制
        DWROrgDao.getCompanyList(true,function(list){
         for(var i=0;i<list.length;i++)
          {
             var li = document.createElement("OPTION");
             li.text = list[i].orgName;
             li.value = list[i].parentOrgId;
             document.all.ddlArea.options.add(li);    
          }
        });
    }

[/code]

可是运行的时候控制台报错

[code="java"]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: sqlMapClient is required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880)
at org.directwebremoting.spring.SpringCreator.getInstance(SpringCreator.java:144)
at org.directwebremoting.spring.SpringCreator.getType(SpringCreator.java:106)
at org.directwebremoting.impl.DefaultCreatorManager.addCreator(DefaultCreatorManager.java:118)
at org.directwebremoting.impl.DefaultCreatorManager.addCreator(DefaultCreatorManager.java:100)
at org.directwebremoting.impl.DwrXmlConfigurator.loadCreate(DwrXmlConfigurator.java:274)
at org.directwebremoting.impl.DwrXmlConfigurator.loadAllows(DwrXmlConfigurator.java:224)
at org.directwebremoting.impl.DwrXmlConfigurator.configure(DwrXmlConfigurator.java:170)
at org.directwebremoting.impl.ContainerUtil.configureFromDefaultDwrXml(ContainerUtil.java:264)
at org.directwebremoting.impl.ContainerUtil.configureContainerFully(ContainerUtil.java:421)
at org.directwebremoting.servlet.DwrServlet.init(DwrServlet.java:79)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: sqlMapClient is required
at org.springframework.orm.ibatis.SqlMapClientTemplate.afterPropertiesSet(SqlMapClientTemplate.java:144)
at org.springframework.orm.ibatis.support.SqlMapClientDaoSupport.checkDaoConfig(SqlMapClientDaoSupport.java:104)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 30 more
2011-08-12 09:34:34 org.directwebremoting.util.CommonsLoggingOutput.error(CommonsLoggingOutput.java:83) [ERROR] Error loading class for creator 'SpringCreator[DWROrgDao]'.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orgDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: sqlMapClient is required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880)
at org.directwebremoting.spring.SpringCreator.getInstance(SpringCreator.java:144)
at org.directwebremoting.spring.SpringCreator.getType(SpringCreator.java:106)
at org.directwebremoting.impl.DefaultCreatorManager.addCreator(DefaultCreatorManager.java:118)
at org.directwebremoting.impl.DefaultCreatorManager.addCreator(DefaultCreatorManager.java:100)
at org.directwebremoting.impl.DwrXmlConfigurator.loadCreate(DwrXmlConfigurator.java:274)
at org.directwebremoting.impl.DwrXmlConfigurator.loadAllows(DwrXmlConfigurator.java:224)
at org.directwebremoting.impl.DwrXmlConfigurator.configure(DwrXmlConfigurator.java:170)
at org.directwebremoting.impl.ContainerUtil.configureFromDefaultDwrXml(ContainerUtil.java:264)
at org.directwebremoting.impl.ContainerUtil.configureContainerFully(ContainerUtil.java:421)
at org.directwebremoting.servlet.DwrServlet.init(DwrServlet.java:79)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: sqlMapClient is required
at org.springframework.orm.ibatis.SqlMapClientTemplate.afterPropertiesSet(SqlMapClientTemplate.java:144)
at org.springframework.orm.ibatis.support.SqlMapClientDaoSupport.checkDaoConfig(SqlMapClientDaoSupport.java:104)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 30 more

[/code]

10个回答

直接在[code="java"]SqlMapClientFactoryBean[/code]类的方法:
[code="java"] protected SqlMapClient buildSqlMapClient(
Resource[] configLocations, Resource[] mappingLocations, Properties properties)
throws IOException {[/code]
设置断点调试一下,看看到底传入的“configLocations”哪里不对。

就是它说的意思,你这个userDao需要一个sqlMapClient(应该是通过属性设置)。你没有设置。于是在调用初始化函数的时候出错了。

你的DAO为什么没有注入sqlSessionFactory呢?我一般都是这样的:
[code="java"]






[/code]

[quote]我用的是ibatis 你这个是mybatis的配置,有区别吗?ibatis需要怎么配置呢? 我有用到 [/quote]
原理的是一样的。如果是ibatis你要注入的是:
[code="java"]org.springframework.orm.ibatis.SqlMapClientFactoryBean[/code]
把我上面的SqlSessionFactoryBean替换就好了。

[code="java"] [/code]
这个设置的地址不对,这样不是绝对路径,spring找不到。你把sqlMapConfig.xml放到classes里面去,然后把这个改成:
[code="java"] [/code]

这孩子,一碰到问题就问

[quote]这个是公司的项目,不能这样子改配置的,有其他的办法米? [/quote]
你spring的配置文件放在哪里?

sqlMapConfig.xml和spring配置在同一目录的话,直接把
[code="java"] [/code]
改成:


再试试。

这样,
[code="java"] [/code]
“WEB-INF”前面加个斜杠。

我把自己的配置改了,放到web-inf下,都是可以的啊:

web.xml
[code="java"]

contextConfigLocation
/WEB-INF/applicationContext.xml

[/code]

applicationContext.xml
[code="java"]




[/code]

日志出来正常:
[code="java"]2011-08-12 13:07:58,593 WEB-MES [main] DEBUG o.m.s.SqlSessionFactoryBean - Parsed configuration file: 'ServletContext resource [/WEB-INF/mybatis-config.xml]'[/code]

检查一下你文件的位置!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问