私はepServiceとepEntity(dbアクセス用のファクトリクラス)として2つのJavaプロジェクトを持っています。また、コントローラを含むepWebという別のSpringプロジェクトがあり、これはRest APIです。 今、epEntityの中にある春のプロジェクトepWebのクラスをautowireしたいと思います。 私は正常にepWebプロジェクト内のクラスをautowiredしましたが、私は別のプロジェクトからクラスをautowireできませんでした。 誰かがこれを行うことを提案しています。 これは、stackoverflowに関する無関係の質問であれば、これを削除してください。別のプロジェクトにあるクラスをオートワイヤする方法
私は私の暗示が両方のプロジェクトでは、スプリング-config.xmlファイルを作成することです パブリッククラスマッパー{
@Autowired
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Autowired
private AppointmentFactory af;
@Autowired
private AppointmentController ac;
}
MVC-ディスパッチャ-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.mobios.ep.web.controllers" />
<!-- <context:component-scan base-package="com.mobios.ep.services" />
<context:component-scan base-package="com.ombios.ep.entity.factory" /> -->
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="1048576"/>
</bean>
</beans>
同じスプリングアプリケーションコンテキスト内に存在するBeanをオートワイヤすることができます。 2つのプロジェクトが独立して配備されている場合、それぞれに独自のアプリケーションコンテキストがあるため、実行しようとしていることを達成する方法がありません。 – lzagkaretos
答えをありがとう。 epWebプロジェクトは、epServiceとepEntityの両方に依存します。だから、私はepWebだけを配備しました。これは、epWeb(Spring)プロジェクトコードがepEntity – Nishantha
の中のクラスにアクセスできることを意味します。次に、コントローラなどを含む関連パッケージの@ComponentScan(basePackages = {"... package ...."})そこにはたくさんありません、あなたは '@Configuration'クラスでそれらをBeanとして宣言することができます。 – lzagkaretos