1

我已将我的 Maven 项目拆分为多个模块。在其中一个模块 service-module 中,我有一个带有 @Service 注释的 SomeBusinessDelegate 类,在另一个模块 service-api (服务模块依赖于该模块)中,我有一个由 SomeBusinessDelegate 实现的接口 ISomeBusinessDelegate . 当我使用 Maven 进行清理/安装时,整个多模块项目都会构建和编译。我已经设置了我的 applicationContext.xml(位于服务模块中)以扫描正确的 bean,但是当我尝试在 tomcat 7 上部署时,我收到一个异常,告诉我 ISomeBusinessDelegate 没有任何可用的 bean 实现它“不满足类型 [interface com.xyzISomeBusinessDelegate]:预计至少有 1 个匹配的 bean”。有什么明显的我' 我做错了吗?我需要在 service-api 模块中添加另一个 applicationContext.xml 吗?

应用程序上下文.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<context:component-scan
    base-package="com.x.y.z.request, com.x.y.z.service, com.x.y.z.dao" />
<context:annotation-config />
<tx:annotation-driven />
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbc:postgresql://localhost:5432/db" />
    <property name="username" value="user" />
    <property name="password" value="password" />
</bean>
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    p:dataSource-ref="dataSource" p:jpaVendorAdapter-ref="jpaAdapter">
    <property name="loadTimeWeaver">
        <bean
            class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    </property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
    p:entityManagerFactory-ref="entityManagerFactory" />
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
    <property name="showSql" value="true" />
</bean>

请求服务.java

package com.x.y.z.request;

@Component
@Path("/request")
public class RequestService
{
    @Autowired
    private ISomeBusinessDelegate delegate;

}

SomeBusinessDelegate.java(ISomeBusinessDelegate.java存在于service-api模块的com.xyzservice中)

package com.x.y.z.service;

@Service
public class SomeBusinessDelegate extends GenericBusinessDelegate implements ISomeBusinessDelegate
{
    @Autowired
    private ISomeDao dao;

    @Override
    @Transactional(readOnly = true)
    public List<ISomething> getSomeThings()
    {
         return dao.someDaoCall();
    }
}

SomeDao.java(GenericDao 包含用 @PersistenceContext 注释的 EntityManager)

package com.x.y.z.dao;

@Repository
public class SomeDao extends GenericDao implements ISomeDao
{
    @Override
    public List<ISomething> someDaoCall()
    {
        //does some sql call
    }
}
4

0 回答 0