[size=14px]问题描述:一个项目分为6个模块分别用A,B,C,D,E,F表示,分组做项目
Hibernate方面:实体类公用
spirng配置文件:一共七个分别是
bean-default.xml,bean-A.xml,bean-B.xml,bean-C.xml,bean-D.xml,bean-E.xml,bean-F.xml
bean-default.xml 主要功能配置sesssionFactory和事务管理器
A,B,C,D,E,F配置文件中第一句配置都是<import resource="classpath:beans-default.xml"/>这样每个配置文件都不用配置sessionFactory和事务了
struts配置文件:一共是6个
struts-config-A.xml,struts-config-B.xml,struts-config-C.xml,struts-config-D.xml,struts-config-E.xml,struts-config-F.xml
用status-config-A.xml举例
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
 <set-property value="/WEBINF/classes/A/bean-A.xml"property="contextConfigLocation"/>
 </plug-in>
像这样每个struts配置文件都会引入对应的spring配置文件
然后在web.xml 配置struts配置文件
 <init-param>
      <param-name>config</param-name>
      <param-value>所有的struts配置文件</param-value>
 </init-param>
以上是我配置的一种方式tomcat启动不会报错,点击D模块功能没有问题,但是点击B模块功能就会抛出异常org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '/customer' is defined
(因为struts配置文件是按A,B,C,D,E,F 在web.xml中配置的,也就是点击D没问题,而点击B确出错了,所以我认为和加载顺序没有关系)
还有一种配置方式就是
白上边的struts中的plug-in全部删掉,然后再web.xml中配置
<context-param>  
  <param-name>contextConfigLocation </param-name>  
  <param-value>这里只加载了bean-default.xml,bean-B.xml,bean-D.xml(我只做了两个模块)</param-value>  
  </context-param>  
  <listener>  
   <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>  
  </listener>  
启动Tomcat抛出异常
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/plan' defined in ServletContext resource [/WEB-INF/classes/net/crm/teamF/salMana/beans_salMana.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5] to required type [net.crm.teamF.salMana.biz.CstCustomerBiz] for property 'cstCustomerBiz'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy5] to required type [net.crm.teamF.salMana.biz.CstCustomerBiz] for property 'cstCustomerBiz': no matching editors or conversion strategy found
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessException details (1) are:
PropertyAccessException 1:
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5] to required type [net.crm.teamF.salMana.biz.CstCustomerBiz] for property 'cstCustomerBiz'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy5] to required type [net.crm.teamF.salMana.biz.CstCustomerBiz] for property 'cstCustomerBiz': no matching editors or conversion strategy found
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy5] to required type [net.crm.teamF.salMana.biz.CstCustomerBiz] for property 'cstCustomerBiz': no matching editors or conversion strategy found
抛出了这个异常让我纠结了,我尝试在web.xml分别加载sping配置文件
第一次加载bean-default.xml和bean-B.xml Tomcat启动没错运行用能正常
第二次加载bean-default.xml和bean-D.xml Tomcat启动没错运行用能正常
从这里我猜出应该是spring配置文件bean(A-F)中的<import resource="classpath:beans-default.xml"/>语句用冲突但是
所以我这么做/还是加载bean-default.xml,bean-B.xml,bean-D.xml 但是我分情况的把B,D文件中的<import />语句去掉
可是还是跑出了上面的异常(Tomcat清过,环境重启过都是一样的)
求指教本人在北大青鸟上学(马上毕业)这是java方面的最后一个项目(客户关系管理系统)项目的框架是我搭建的,弄着这么多配置文件,这样每个人写自己的模块,自己的配置文件,虽然有冗余,但是互不干扰,可是没有想到还没和项目就出现问题了,求高手指教公司里的项目框架是怎么搭建的~~~~(>_<)~~~~ 神呀救救我吧。
不知道以上的我描叙清楚了没有,还有就是我没有尝试在plugin中配置不在web.xml然后再分别尝试删除<import />
[/size]

解决方案 »

  1.   

    web.xml配置没有问题。报的错是:
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5] to required type
    spring在初始化的bean的时候注入bean的属性发现类型和传入的不相同,所以报错。
    检查一下beans_salMana.xml这个配置文件里的bean的配置可以参考文章:
    http://blog.csdn.net/ma_shijie/archive/2010/11/04/5988331.aspx
    里面有ssh框架集成的部分。
      

  2.   

    spring在初始化的bean的时候注入bean的属性发现类型和传入的不相同,所以报错。……出项问题应该就是<import /> 引入的那个主要spring配置文件吧
      

  3.   

    好长呀!!!
    我是使用第二种方式即:<!-- Spring ApplicationContext配置文件的路径,可使用通配符*,多个路径用,号分隔,此参数用于后面的Spring-Context loader -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:application*.xml</param-value>
    </context-param>
    <!--对Spring容器进行实例化 -->
    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>其实不管你的配置文件再多,在内存里都会拼接成一个文件。
    所以,你的bean-default.xml 里面的内容被加载了多次..
      

  4.   

        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-valueclasspath:application*.xml</param-value>
        </context-param>
      

  5.   

    我想这就是你单独运行 没有问题,组合到一起运行时,却出现了Error setting property values
    的问题.
      

  6.   

    我又不想配置把配置文件弄到一起,那样创建的bean太多,不好维护,我也知道被加载了多次,可我是尝试删除其中的一个就是没有作用抛出的异常一样……
      

  7.   

    你的这句话:
    bean-default.xml 主要功能配置sesssionFactory和事务管理器
    A,B,C,D,E,F配置文件中第一句配置都是<import resource="classpath:beans-default.xml"/>这样每个配置文件都不用配置sessionFactory和事务了
    struts配置文件
    修改为:
    在bean-default.xml 中
    <import resource="classpath:beans-A.xml"/>
    <import resource="classpath:beans-B.xml"/>
    <import resource="classpath:beans-C.xml"/>
    <import resource="classpath:beans-D.xml"/>
    <import resource="classpath:beans-E.xml"/>
    <import resource="classpath:beans-F.xml"/>
    不知道这样是不是符合你的想法..
      

  8.   

    如果可以的话 如果在web.xml 中配置spring文件 就表示了只要配置bean-defalut.xml
    就行了吧\(^o^)/
      

  9.   

    我修改完了,启动时候有抛异常了,不过这回我仔细看了看,发现配置文件中的bean命名尽量模块名+开发人员编号,模块之间不可避免的有联系的,所以一样的功能的ben我取的名字相同……(我傻了就是)……
    修改完之后启动Tomcat没有报错,运行也正常(*^__^*) 嘻嘻……谢谢了
      

  10.   

    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property value="/WEBINF/classes/A/bean-A.xml"property="contextConfigLocation"/>
    </plug-in>
    每个文件里都要配么????