Spring Boot在自动配置组件时抛出Caused by: java.lang.IllegalArgumentException: null
。我的null
文件中没有application.properties
属性。这是一个谜。
我尝试了一切。错误消息表明问题出在文件中的factory.core属性。我尝试将其删除,但出现了一个更通用的错误。如果我将factory.core放回原处,那么错误会专门抱怨它。
我的application.properties具有以下四个:
factory.protocol=http
factory.host=localhost
factory.core=recommend
factory.port=8983
我有这些注释
@Configuration
@ConfigurationProperties("factory")
我的代码只有这些字段的设置方法和获取方法。
private String protocol;
private String host;
private int port;
private String core;
Spring Boot将其写出来。
Description:
Failed to bind properties under 'factory' to com.ot.cem.recommender.engine.ClientFactory$$EnhancerBySpringCGLIB$$1530d0ff:
Property: factory.core
Value: recommend
Origin: class path resource [application.properties]:4:14
Reason: Failed to bind properties under 'factory' to com.ot.cem.recommender.engine.ClientFactory$$EnhancerBySpringCGLIB$$1530d0ff
Action:
Update your application's configuration
The exception is
Caused by: java.lang.IllegalArgumentException: null
at java.lang.reflect.Array.newArray(Native Method) ~[na:1.8.0_162]
at java.lang.reflect.Array.newInstance(Array.java:75) ~[na:1.8.0_162]
at org.springframework.boot.context.properties.bind.Bindable.box(Bindable.java:255) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.context.properties.bind.Bindable.of(Bindable.java:248) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
答案 0 :(得分:0)
答案 1 :(得分:0)
您是否在依赖项中包括配置注释处理器?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
那个或Spring确实找不到您的application.properties
文件。您也可以通过注释每个字段来进行测试,例如@Value("factory.prototype")
答案 2 :(得分:0)
感谢您的答复。我尝试删除@Configuration,但结果相同。 link2在两个注释之间有很好的解释。我忘了在原始帖子中声明,我还设置了@Component批注,因为我可以自动装配要在另一个类中配置的类。
我使用Gradle,所以我有 编译(“ org.springframework.boot:spring-boot-configuration-processor:2.0.6.RELEASE”)。我阅读了文档链接。我认为Spring可以找到application.properties,因为错误提到了其中一个属性。就我而言,是factory.core。
不确定该怎么做。据我所确定,它应该可以工作。