6
1つのプロジェクトでデータアクセスを行い、別のプロジェクトでそれをspring
jarという名前で使用するプロジェクトがあります。 gradle maven-publish
プラグインを使用してjarファイルを作成しました。私はRepository
が使用されている。このSpring - 他のJarからのリポジトリがnullです。どのように初期化するのですか?
@ContextConfiguration(locations = {"classpath*:spring-config.xml"})
@Transactional
public class TenantProvisioningManagerTest extends AbstractTestNGSpringContextTests {}
クラスのように私の他のプロジェクトのテストケースでは、このジャーを初期化します。私はこの
public class TenantProvisioningManager {
private static final Logger logger = LogManager.getLogger(TenantProvisioningManager.class);
@Autowired
TProductRepository tProductRepository;
}
リポジトリのように使用ここnull
です。この別のプロジェクトで他のjarからリポジトリを初期化するには?
spring-config.xml
:TenantProvisioningManager
は別々のプロジェクトでありながら
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
">
<context:property-placeholder
location="file://#{systemEnvironment['GRADLE_USER_HOME']}/gradle.properties"/>
<!-- the base package for spring data jpa repository interfaces -->
<jpa:repositories base-package="com.asklytics.dao.repos" />
<!-- Enable the component scan (auto wiring etc) for the following package -->
<context:component-scan base-package="com.asklytics" />
<!-- Make sure the following is specified to enable transaction -->
<tx:annotation-driven />
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- This defines the entity manager factory with some custom properties -->
<bean id='entityManagerFactory' class='org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean'>
<property name="persistenceUnitName" value="persitanceUnit"/>
<property name='dataSource' ref='dataSource' />
</bean>
<bean id='dataSource' class='org.springframework.jdbc.datasource.DriverManagerDataSource'>
<property name='driverClassName' value='com.mysql.jdbc.Driver' />
<property name='url' value="${awsCamelDbUrl}" />
<property name='username' value="${awsCamelDbUsername}" />
<property name='password' value="${awsCamelDbPassword}" />
</bean>
spring-config.xml
とTProductRepository
は、他のプロジェクトです。
クラスパスにspring-data-jpaがありますか?これらのリポジトリが存在するパッケージをスキャンするスプリングコンフィグレーションですか?また、 'NoSuchBeanDefinitionException'を投げるのではなく' null'であるという事実は、あなたの 'TenantProvisioningManager'がSpringによって管理されていないことを意味し、あなたのautowiringは壊れています。 – nbrooks
はいspring-data-jpaはクラスパス上にあります。パッケージのスキャンについてはどうすれば確認できますか? 'TenantProvisioningManager'がSpringによって管理されるようにするにはどうしたらいいですか? –
'spring-config.xml'の内容を投稿します。また、 'TenantProvisioningManager'と' TProductRepository'はどのパッケージにありますか? – manish