我已将我的maven项目拆分为多个模块。在其中一个模块service-module中,我有一个带有@Service注释的SomeBusinessDelegate类,而在另一个模块service-api(服务模块依赖于它)中,我有一个由SomeBusinessDelegate实现的接口ISomeBusinessDelegate 。当我使用maven进行清理/安装时,整个多模块项目将构建和编译。我已经设置了我的applicationContext.xml(在service-module中)来扫描正确的bean但是当我尝试在tomcat 7上部署时,我得到一个异常,告诉我ISomeBusinessDelegate没有任何可用的bean实现它“不满意的依赖关系type [interface com.xyzISomeBusinessDelegate]:期望至少有一个匹配的bean“。有什么明显的东西我做错了吗?我是否需要在service-api模块中使用另一个applicationContext.xml?
的applicationContext.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>
RequestService.java
package com.x.y.z.request;
@Component
@Path("/request")
public class RequestService
{
@Autowired
private ISomeBusinessDelegate delegate;
}
SomeBusinessDelegate.java(ISomeBusinessDelegate.java存在于service-api模块的com.x.y.z.service中)
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
}
}