我正在将Spring Boot 2.2.7与spring-data-mongodb一起使用。 IDE:Intellij Idea社区版2020。
我有一个公共项目,该项目托管通用模型,存储库和服务,另一个项目托管名为 gateway 的控制器。 一切运行良好,直到我在 common 项目中将枚举从 NodeTypeEnum 重命名为 poductTypeEnum 。
运行Spring gateway 应用程序时,我得到
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]
错误来自的代码:
枚举(常见项目)
public enum ProductTypeEnum {
SENSOR,FIELD,SINK,BASE_STATION,DATA_CENTER
}
使用枚举(常见项目)
@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);
}
service.conf(网关项目)
@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);
}
}
看起来似乎是旧的nodeType属性存储在某处,所以它非常坚固。我检查了由 common 构建项目生成的jar在maeven存储库中是否是最新的,没关系。我已经使缓存无效/重新启动Idea,重新生成项目。甚至将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>
解决方案
网关项目pom.xml中缺少spring-start-web依赖项