`

165. Spring Boot @ConfigurationProperties的locations过时【从零开始学Spring Boot】

阅读更多

 

【视频&交流平台】

à SpringBoot视频

http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share

à SpringCloud视频

http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share

à Spring Boot源码

https://gitee.com/happyangellxq520/spring-boot

à Spring Boot交流平台

http://412887952-qq-com.iteye.com/blog/2321532

 

需求缘起

 在录制Spring Boot自定义属性的时候,发现@ConfigurationPropertieslocations已经过时了,如下代码:

@ConfigurationProperties(prefix="email",locations={"classpath:email.properties"})
public class Email2Properties {
}

 

       如上代码情况locations已经过时,不建议使用了。

 

版本说明:

       出现以上的情况,前提是Spring Boot版本使用的是1.4+以上的版本,如果使用的1.4之前的版本,比如:1.3.3版本的时候,是可以正常使用的。

 

解决之道:

1@EnableConfigurationProperties取消激活自定义的配置类

2采用@Component的方式注册为组件,然后使用@PropertySource来指定自定义的资源目录,如下代码:

@Component
@ConfigurationProperties(prefix="email")
@PropertySource(value={"classpath:email.properties"})
public class Email2Properties {
}

 

可以参考链接:https://github.com/spring-projects/spring-boot/issues/6726

 

 

        

分享到:
评论

相关推荐

    springboot 基础简易实例, maven项目

    <groupId>org.springframework.boot <artifactId>spring-boot-starter-parent <version>2.1.4.RELEASE <relativePath/> <!-- lookup parent from repository --> <groupId>com.example</groupId> ...

    spring boot静态资源部署

    spring boot静态资源部署Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。

    Spring AOP配置源码

    此单元测试基于spring的AbstractJUnit4SpringContextTests,你需要添加spring的关于单元测试的支持 在类上标注@ContextConfiguration(locations="classpath:applicationContext.xml")意思是去classpath路径下加载...

    spring-test.jar

    spring-test.jar 用在junit4以上 在类上写 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"WIN-INF/config/applicationContext.xml" })

    springmvc-ibatis

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop=...

    spring-boot-集成mybatis带分页page

    # Spring Boot 集成 MyBatis, 分页插件 PageHelper, 通用 Mapper ## 项目依赖 ```xml <!--mybatis--> <groupId>org.mybatis.spring.boot <artifactId>mybatis-spring-boot-starter <version>1.1.1 <!...

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: ...

    Spring MVC 入门实例

    如果你手上有一本《Spring in Action》, 那么你最好从第三部分"Spring 在 Web 层的应用--建立 Web 层"开始看, 否则那将是一场恶梦! 首先, 我需要在你心里建立起 Spring MVC 的基本概念. 基于 Spring 的 Web 应用...

    SpringMVC-SSH全注解

    <property name="locations"> <value>classpath:jdbc.properties <!-- 配置數據源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> ${jdbc....

    spring3.2+strut2+hibernate4

    spring3.2+strut2+hibernate4 注解方式。 spring.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...

    SpringMVC+Hibernate全注解整合

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context=...

    ssh框架在application.xml中配置数据源所需jar

    <property name="locations"> <value>classpath:/deploy.properties <!-- 配置sessionFactory <bean id="sessionFactory" class="org.springframework.orm.hibernate3....

    SpringBoot实现本地存储文件上传及提供HTTP访问服务.docx

    别忘记了spring boot 为我们提供了 使用spring.resources.static- locations配置自定义静态文件的位置。 web: upload-path: D:/data/ spring: resources: static-locations: classpath:/META-INF/resources/,...

    基于Redis的分布式配置管理中心.zip

    <property name="locations"> <value>classpath*:app.properties 设置环境变量或JVM启动参数 环境变量方式 export config.server=localhost:6379 export config.environment=dev JVM启动参数方式 -Dconfig....

    iOS 7开发(英文档)

    Most of the time you can just accept the default values for the locations, so go ahead and click “Create.” Xcode then generates two new files for your project: MyClass.h and MyClass.m. They contain ...

    Spring + Hibernate + Struts 事务配置小例子(带提示框等小技巧)

    前几天搞 Spring + Hibernate + Struts 事务配置 ,网上找了好多资料,不过好无语,大多都是 Ctrl + V,浪费俺的宝贵时间 现在我总结配出一套,给大家参考参考,可能有不足,请大家多多交流。 附:内有弹出...

    springCloud微服务

    Spring Boot has an opinionated view of how to build an application with Spring: for instance it has conventional locations for common configuration file, and endpoints for common management and ...

    springboot+mybatis+内置tomcat示例.rar

    mybatis.mapper-locations=classpath:mapping/*Mapper.xml mybatis.type-aliases-package=entity #spring.profiles=development #server.address=127.0.0.1 #端口设置 server.port=8092 #日志配置 ...

    Spring 自定义注解注入properties文件的值jar包

    Spring 自定义注解注入properties文件的值jar包,下面为使用方法 在xml配置文件中,这样加载properties文件 <bean id="propertyConfigurer" class="com.better517na.propertiesComponent.business....

Global site tag (gtag.js) - Google Analytics