Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring-来自其他Jar的存储库为空。如何初始化它?_Spring_Gradle_Spring Data - Fatal编程技术网

Spring-来自其他Jar的存储库为空。如何初始化它?

Spring-来自其他Jar的存储库为空。如何初始化它?,spring,gradle,spring-data,Spring,Gradle,Spring Data,我有一个项目,在一个项目中进行数据访问,并在另一个项目中作为springjar使用它。我使用gradlemaven publish插件创建了jar。我在另一个项目测试用例中初始化了这个Jar,如下所示 @ContextConfiguration(locations = {"classpath*:spring-config.xml"}) @Transactional public class TenantProvisioningManagerTest extends AbstractTestNGS

我有一个项目,在一个项目中进行数据访问,并在另一个项目中作为
spring
jar使用它。我使用
gradlemaven publish
插件创建了jar。我在另一个项目测试用例中初始化了这个Jar,如下所示

@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;
}
类,其中正在使用
存储库
。我以前是这样的

@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

<?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
位于其他项目中,而
tenantprovisionmanager
位于单独的项目中

确保您的
租户ProvisioningManager
也由spring管理。注释为@Component

类路径上是否有spring数据jpa,您的spring配置是否扫描这些存储库所在的包?另外,它是
null
而不是抛出
NoSuchBeanDefinitionException
这一事实可能意味着您的
tenantprovisionmanager
不是由Spring管理的,因此您的自动连接被中断。是的,Spring数据jpa位于类路径上。我如何确认扫描包裹?如何使
tenantprovisionmanager
由Spring管理?发布
Spring config.xml
的内容。另外,什么包是中的
tenantprovisionmanager
TProductRepository
?@manish添加了
spring config.xml
。我甚至觉得提起这个问题很傻,但我会的,因为我没有看到TProductRepository的代码。问题中的jar是您自己编写和编译的jar吗?如果是,TProductRepository是否用@Repository注释?