共享jar

pgpifvop  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(197)

我使用的是springboot2.2.5.release和spring-data-2.2.5.release
我们在不同的git存储库中有多个项目,我正在尝试创建一个公共json存储库,通过共享jar使用mysql json函数。
我在我的公共jar中创建了以下内容,它有一个自动配置

@NoRepositoryBean
public interface JsonRepository <T>{

    int appendToArray(T entity, String arrayPath, Object item, String storeId) throws JsonProcessingException;

    int removeFromArrayByValue(T entity, String arrayPath, String feild, String value, String storeId);
}

配置类

@EnableJpaRepositories(repositoryBaseClass = JsonRepositoryImpl.class,
        repositoryFactoryBeanClass = JsonRepositoryFactoryBean.class
)
@Configuration
public class RepositoryConfig {

}

我有一个 spring.factorie 将此配置为自动配置的“我的资源”中的文件
以及我的实现存储库

@Repository
public interface SettingsRepository extends JsonRepository<Settings>, CrudRepository<Settings, Long> {
}

问题
当我使用我的公共jar(其中包含我创建的所有json公共文件)时,spring数据停止检测所有存储库,并且由于缺少bean,我无法启动应用程序

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'XXXService' defined in file [XXXService.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xxx.XXXRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)

只有在消费项目中添加另一个@configuration时,它才起作用,并且我想让它自动工作,以便在每个我想添加json查询功能的项目上保存对它的定义

@EnableJpaRepositories(
        repositoryBaseClass = JsonRepositoryImpl.class,
        repositoryFactoryBeanClass = JsonRepositoryFactoryBean.class,
        basePackages = "xxx.*"
)
public class CoreConfig {
}

我怎么能修好它??

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题