小编典典

如何自动连接另一个项目中的课程

spring-mvc

我有两个Java项目,分别是epService和epEntity(用于数据库访问的工厂类)。还有另一个名为epWeb的Spring项目,其中包含控制器,这是Rest
API。现在,我想将epEntity内部的类自动连接到spring项目epWeb。我已经成功地在该epWeb项目中自动对类进行了自动接线,但是我无法从另一个项目中对一个类进行自动接线。有人对此有建议,请告诉我。如果这是与stackoverflow无关的问题,请删除它。

我为公共课程Mapper {

@Autowired
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
}
@Autowired
private AppointmentFactory af;
@Autowired
private AppointmentController ac;
}

mvc-dispatcher-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>

阅读 241

收藏
2020-06-01

共1个答案

小编典典

您可以@ComponentScan在主应用程序epWeb中使用批注,以便在epEntity项目中作为Bean(控制器,服务等)存在于项目中的Spring上下文类中进行注册。

@ComponentScan({"com.example.service", "com.example.controlle‌​r"})

另外,请确保@ServiceepEntity项目中对Service实现进行注释。

2020-06-01