【问题标题】:applicationcontext.xml spring servrices from another jarapplicationcontext.xml 来自另一个 jar 的 spring 服务
【发布时间】:2012-11-14 00:50:14
【问题描述】:

快速提问。 当它们在 webApp 使用的另一个 jar 中时,您可以在 applicationContext.xml 中引用 Spring 类吗?

JAR(一个包含我所有的 servries 和 daos 等的通用 jar)在 WAR 文件中,但是当我尝试通过 applicationContext.xml 引用服务时,我收到以下错误:-

Error creating bean with name 'com.myproject.common.test.impl.TestServiceImpl' defined in ServletContext resource [/WEB-INF/context/spring-context.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition

(注意spring-context.xml导入到applicationContext.xml中没有错误。)

我的上下文 XML:

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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/context 
                            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="com.myproject.common.test.impl.TestServiceImpl">
        <property name="genericDao" ref="genericDao" />
    </bean>         
</beans>

我的 App 包都在 com.myproject.web 下 我的常用 JARS 都在 com.myproect.common 下

【问题讨论】:

  • 一旦你做了@combinatorics 提到的事情。确保 jar 文件在您的类路径中。
  • 为 MasterV 干杯,它成功了。

标签: java spring mapping applicationcontext


【解决方案1】:

你的 bean 元素需要一个类属性:

<bean id="myTestServiceImpl" class="com.myproject.common.test.impl.TestServiceImpl">
    <property name="genericDao" ref="genericDao" />
</bean>        

id 属性只是在 bean 文件中其他地方引用 bean 的标识符。 class 属性提供了 bean 所代表的类的名称。

【讨论】:

  • 天哪,我太笨了!从我的 dao-context.xml 复制粘贴并覆盖 id="..." class="..." 并将其变成 id="..."
猜你喜欢
  • 1970-01-01
  • 2018-04-27
  • 1970-01-01
  • 1970-01-01
  • 2016-08-07
  • 1970-01-01
  • 2019-10-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多