【问题标题】:Spring - Beans into classes from another projectSpring - 将 Bean 放入另一个项目的类中
【发布时间】:2018-02-22 12:43:59
【问题描述】:

以前我只有一个名为“projectA”的项目。 我在“projectA”中有一个 XML bean 配置文件“service.xml”,bean 的类为“com.home.karoom.impl.adapter”

<beans 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: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/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<bean id="<bean id="espAdapter" class="com.home.karoom.impl.adapter"> 
<property name="writer" ref="writer" />
</bean>
</beans>

现在,我创建了名为“projectB”的新项目并将 bean 类“com.home.karoom.impl.adapter”移动到“projectB”。

现在,“projectA”中不再存在 bean 类“com.home.karoom.impl.adapter”

如何使用“service.xml”引用“projectB”中的新类位置?

【问题讨论】:

  • 你是用IDE编译吗?
  • @EugenCovaci 是的,我愿意
  • 嗯,spring 2.5 现在已经相当老了,你应该考虑升级。无论如何,xml 文件是在运行时处理的,所以类 com.home.karoom.impl.adapter 必须 存在于运行时类路径中的某个位置。常见的方式是它存在于项目中,最终通过一个库 jar。

标签: java spring


【解决方案1】:

我认为你必须将文件导入到你的项目中

<import resource="classpath:spring-config.xml" />

【讨论】:

    【解决方案2】:

    here 很好地解释了如何在项目之间共享代码/类。

    简短的回答是,您的类 com.home.karoom.impl.adapter 应该放在单独的项目中并打包为 jar。然后作为依赖项添加到您的项目(A 和 B)中。

    请务必遵守约定,并以大写字母开头的类命名

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      • 2017-06-18
      • 2011-07-04
      • 2018-12-13
      • 1970-01-01
      相关资源
      最近更新 更多