spring boot Configuration Annotation Proessor not found in classpath
2017-12-19 14:38
645 查看
转载来自:http://blog.csdn.net/expect521/article/details/77151094
@ConfigurationProperties(prefix=”author”) 没有指定classpath时,IDEA提示没有找到classpath。
在浏览器中访问的结果是null 0是由于在没指定路劲的情况下,默认在resource下的applications.properties中查找,如果找到则返回值,如果没有找到则返回默认值null/0/false…
根据提示的not found in classpath,查询此注解的使用关于怎么指定classpath,进而查询location,spring boot1.5以上版本@ConfigurationProperties取消location注解
解决方案:
在配置类中采用@Component的方式注册为组件,然后使用@PropertySource来指定自定义的资源目录.(本人测试用@Service代替@Component也可以的)
有以下三种解决方案:
第一种:在resource中创建author.properties,并指明@PropertySource(“author.properties”) ,即默认在resource下找此文件,找到返回一个值,找不到则报错,报文件找不到,打不开。
第二种: 在resource下创建config文件夹,把author.properties放在config下,访问方式为:@PropertySource(“classpath:config/book.properties”)
第三种: 直接写在application.properties中(不建议这么做,但如果时全局变量提倡这种方法),当写在此文件中时,不需要指明资源文件路劲,只需要指明前缀即可。如下:
@ConfigurationProperties(prefix=”author”) 没有指定classpath时,IDEA提示没有找到classpath。
在浏览器中访问的结果是null 0是由于在没指定路劲的情况下,默认在resource下的applications.properties中查找,如果找到则返回值,如果没有找到则返回默认值null/0/false…
分析
出现spring boot Configuration Annotation Proessor not found in classpath的提示是在用了@ConfigurationProperties这个注解时,所以问题出现在ConfigurationProperties注解。根据提示的not found in classpath,查询此注解的使用关于怎么指定classpath,进而查询location,spring boot1.5以上版本@ConfigurationProperties取消location注解
解决方案:
在配置类中采用@Component的方式注册为组件,然后使用@PropertySource来指定自定义的资源目录.(本人测试用@Service代替@Component也可以的)
有以下三种解决方案:
第一种:在resource中创建author.properties,并指明@PropertySource(“author.properties”) ,即默认在resource下找此文件,找到返回一个值,找不到则报错,报文件找不到,打不开。
第二种: 在resource下创建config文件夹,把author.properties放在config下,访问方式为:@PropertySource(“classpath:config/book.properties”)
第三种: 直接写在application.properties中(不建议这么做,但如果时全局变量提倡这种方法),当写在此文件中时,不需要指明资源文件路劲,只需要指明前缀即可。如下:
相关文章推荐
- spring boot Configuration Annotation Proessor not found in classpath
- Spring Boot之 Configuration Annotation Proessor not found in classpath解决方法
- spring boot Configuration Annotation Proessor not found in classpath
- 【SpringBoot】Spring Boot Configuration Annotation Processor not found in classpath
- Spring Boot 踩坑之路之 Configuration Annotation Proessor not found in classpath
- Spring Boot Configuration Annotion Processor not found in classpath
- VS Code打开使用IDEA搭建的Spring Boot项目运行提示"snakeyaml was not found on the classpath"错误
- maven/plugin开发:插件版本不匹配导致的报错:Method: ‘name’ not found in class in ParameterAnnotationContent
- No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/package/java/hibernat
- Idea Error:java: System Java Compiler was not found in classpath:
- build.gradle warning: spring boot gradle bootstrap class path not set ...
- Spring Boot:The Bean Validation API is on the classpath but no implementation could be found
- Spring Boot No auto configuration classes found in META-INF/spring.factories
- 异常解决 java.io.FileNotFoundException: class path resource [spring/applicationContext_*.xml]
- No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath解决
- Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClass
- 1.WARN:No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath
- 启动hive报错:("com.mysql.jdbc.Driver") was not found in the CLASSPATH
- [置顶] The specified datastore driver ("com.mysql.jdbc.Driver") was not found in the CLASSPATH
- java.io.FileNotFoundException: class path resource [templates/] spring-cloud-netflix-eureka-server