Mongodb 创建bean时Spring boot mongo存储库未满足依赖关系

Mongodb 创建bean时Spring boot mongo存储库未满足依赖关系,mongodb,spring-boot,javabeans,mongorepository,Mongodb,Spring Boot,Javabeans,Mongorepository,我正在使用SpringBoot2.2.7和SpringDataMongoDB。IDE:Intellij Idea社区版2020 我有一个common项目,它托管公共模型、存储库和服务,还有一个项目托管名为gateway的控制器。 一切正常,直到我在common项目中将枚举从nodetypeneum重命名为PoductTypeEnum 运行spring网关应用程序时,我得到 org.springframework.beans.factory.UnsatisfiedDependencyExcepti

我正在使用SpringBoot2.2.7和SpringDataMongoDB。IDE:Intellij Idea社区版2020

我有一个common项目,它托管公共模型、存储库和服务,还有一个项目托管名为gateway的控制器。 一切正常,直到我在common项目中将枚举从nodetypeneum重命名为PoductTypeEnum

运行spring网关应用程序时,我得到

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servicesConf': Unsatisfied dependency expressed through field 'catalogRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catalogRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property nodeType found for type Product!
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
错误产生的代码:

枚举(通用项目)

使用枚举(common项目)初始化

目录存储库(**公共*项目)

这很奇怪,因为一个旧的nodeType属性似乎被存储在某个地方。我已经检查过,由common构建项目生成的jar在maeven存储库中是最新的,没有问题。我已经放弃了缓存/重启的想法,重建项目。即使将ProductTypeEnum重命名回NodeTypeEnum,也无法解决问题

有什么想法吗

提前谢谢


网关pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>org.open_si</groupId>
    <artifactId>udc-gateway</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Gateway</name>
    <description>Gateway for UDC project</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.open_si</groupId>
            <artifactId>udc-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.6</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.6</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.6</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

4.0.0
org.springframework.boot
spring启动程序父级
2.2.7.发布
org.open_si
udc网关
0.0.1-快照
战争
网关
UDC项目网关
11
org.open_si
通用的
0.0.1-快照
org.springframework.boot
弹簧启动机amqp
org.springframework.boot
spring启动程序数据mongodb
org.springframework.boot
春季启动邮件
org.springframework.boot
SpringBootStarterWeb
com.fasterxml.jackson.core
杰克逊核心
2.9.6
com.fasterxml.jackson.core
杰克逊注释
2.9.6
com.fasterxml.jackson.core
杰克逊数据绑定
2.9.6
org.projectlombok
龙目
真的
org.springframework.boot
弹簧启动机tomcat
假如
org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机
org.springframework.amqp
春兔试验
测试
org.springframework.boot
springbootmaven插件

解决方案


网关项目pom.xml

中缺少spring start web依赖项,请尝试在两个项目中运行
mvn clean install-U
,谢谢@Ehab Qadah您的解决方案修复了我问题的另一部分。实际上,idea似乎并不总是重新加载maven依赖项,即使日志中显示了这些依赖项。最初的问题是我的网关项目pom中的spring start web missong。xml@Emmanuel布鲁内特我有完全相同的问题时,你重命名接口。我不理解你的解决方案。添加“spring start web”是什么意思?你能告诉我这个依赖关系吗?我已经有了spring boot starter web,但始终存在相同的问题。请尝试在两个项目中运行
mvn clean install-U
。谢谢@Ehab Qadah您的解决方案修复了我问题的另一部分。实际上,idea似乎并不总是重新加载maven依赖项,即使日志中显示了这些依赖项。最初的问题是我的网关项目pom中的spring start web missong。xml@Emmanuel布鲁内特我有完全相同的问题时,你重命名接口。我不理解你的解决方案。添加“spring start web”是什么意思?你能告诉我这个依赖关系吗?我已经有了SpringBootStarterWeb,但总是有同样的问题。
@Data
@EqualsAndHashCode
@Document(collection = "catalog")
public class Product  implements Serializable {

    @Id
    private String _id;

    /* internal UUID */
    @Indexed(unique = true)
    @Setter(AccessLevel.NONE)
    private String uuId = new UdcId().getValue();
    @Indexed
    private ProductTypeEnum productType;
    ........
@EnableMongoRepositories
public interface CatalogRepository extends MongoRepository<Product, String> {

    @Query(sort = "{'model':1}")
    public List<Product> findAllByCapabilitiesContaining(String capability, Pageable paging);

    @Query(sort = "{'model':1}")
    public List<Product> findAllByModel(TextCriteria model, Pageable paging);

    @Query(sort = "{'model':1}")
    public List<Product> findAllByModelIsContainingIgnoreCase(String model, Pageable paging);


    @Query(sort = "{'model':1}")
    public List<Product> findAllByNodeType(ProductTypeEnum nodeType, Pageable paging);

    public List<Product> findAllByManufacturerIsContainingIgnoreCase(String manufacturer, Pageable paging);

    public Product findByUuId(String uuId);

    @Query(sort = "{'model':1}")
    public List<Product> findAllBy(Pageable paging);

}
@Configuration
@EnableMongoRepositories
public class ServicesConf {

    @Autowired
    CatalogRepository catalogRepository;
    @Autowired
    ComponentRepository componentRepository;
    @Autowired
    ParamRepository paramRepository;
    @Autowired
    SensorRepository sensorRepository;
    @Autowired
    OrganizationRepository organizationRepository;
    @Autowired
    SampleRepository sampleRepository;


    @Bean
    CatalogPersistenceService catalogPersistenceService() {
        return new CatalogPersistenceService(catalogRepository, stockPersistenceService());
    }

    @Bean
    ParamPersistenceService paramPersistenceService() {
        return new ParamPersistenceService(paramRepository);
    }

    @Bean
    SensorPersistenceService sensorPersistenceService() {
        return new SensorPersistenceService(sensorRepository);
    }

    @Bean
    OrganizationPersistenceService organizationPersistenceService() {
        return new OrganizationPersistenceService(organizationRepository);
    }

    @Bean
    StockPersistenceService stockPersistenceService() {
        return new StockPersistenceService(componentRepository, this.sensorPersistenceService());
    }

    @Bean
    SamplePersistenceService collectPersistenceService(){
        return new SamplePersistenceService(sampleRepository);
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>org.open_si</groupId>
    <artifactId>udc-gateway</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Gateway</name>
    <description>Gateway for UDC project</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.open_si</groupId>
            <artifactId>udc-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.6</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.6</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.6</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>