spring boot Configuration Annotation Proessor not found in classpath

编程知识 更新时间:2023-04-05 03:48:37

@ConfigurationProperties(prefix=”author”) 没有指定classpath时,IDEA提示没有找到classpath。

在浏览器中访问的结果是null 0是由于在没指定路劲的情况下,默认在resource下的applications.properties中查找,如果找到则返回值,如果没有找到则返回默认值null/0/false…

分析


  1. 出现spring boot Configuration Annotation Proessor not found in classpath的提示是在用了@ConfigurationProperties这个注解时,所以问题出现在ConfigurationProperties注解。
  2. 根据提示的not found in classpath,查询此注解的使用关于怎么指定classpath,进而查询location,spring boot1.5以上版本@ConfigurationProperties取消location注解
  3. 解决方案:

在配置类中采用@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

本文发布于:2023-04-05 03:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/c57fc015d735442680a5fc43b2874ff1.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Configuration   boot   spring   classpath   Proessor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 44600文章数
  • 14阅读数
  • 0评论数