spring-properties

spring maven profile - set properties file based on compilation profile

随声附和 提交于 2021-02-10 12:14:02
问题 I would create some compilation profiles like these: profile name: dev profile name: test profile name: production In src/main/resources I have 3 folders: dev/file.properties test/file.properties production/file.properties Each file contains different values for this properties: - my.prop.one - my.prop.two - my.prop.three After that I would set in Spring classes something like these: @Configuration @PropertySource("file:${profile_name}/file.properties") public class MyConfig{ } How can I do?

spring maven profile - set properties file based on compilation profile

て烟熏妆下的殇ゞ 提交于 2021-02-10 12:12:55
问题 I would create some compilation profiles like these: profile name: dev profile name: test profile name: production In src/main/resources I have 3 folders: dev/file.properties test/file.properties production/file.properties Each file contains different values for this properties: - my.prop.one - my.prop.two - my.prop.three After that I would set in Spring classes something like these: @Configuration @PropertySource("file:${profile_name}/file.properties") public class MyConfig{ } How can I do?

Using @Value with condition in spring in order to map value to string

被刻印的时光 ゝ 提交于 2020-08-27 06:34:05
问题 I have a application.properites file with the following: xxx.xxx = sandbox xxx.sandbox = 123 xxx.production = 456 I would like to map to a string value 123 in case xxx.xxx == sandbox and 456 in case xxx.xxx == production ... public class temp { @Value("${??????}") private String token; } is it possible to fill in a condition incited of the ?????? that will map the token to 123 or 456 according to xxx.xxx ? 回答1: A simple way in case someone will hit this question: @Value("#{'${xxx.xxx}'==

Spring Boot bind @Value to Enum case insensitive

梦想的初衷 提交于 2020-01-02 00:53:05
问题 Enum public enum Property { A, AB, ABC; } Field @Value("${custom.property}") protected Property property; application.properties (lower case) custom.property=abc When I'm running application I have an error: Cannot convert value of type [java.lang.String] to required type [com.xxx.Property]: no matching editors or conversion strategy found. Whereas (upper case): custom.property=ABC Works fine. Is there a way to bind the value case insensitive? Like ABC , Abc , AbC , abc any pattern should

spring boot always using the same profile

*爱你&永不变心* 提交于 2019-12-24 02:28:06
问题 I am using spring boot 1.5.2, and using profiles but I found a very strange thing. my spring boot resources folder like this: configs in application.yml spring: profiles: active: @profileActive@ application-dev.yml spring: profiles: dev datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/db1 username: root password: server: port: 8080 application-test.yml spring: profiles: test datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost

Use Java util properties instead of propertyplaceholder configurator in springbeans.xml

依然范特西╮ 提交于 2019-12-11 12:52:27
问题 I need to dynamically placehold the property values in springbeans.xml using Java.util.properties instead of PropertyPlaceHolderConfigurator in Spring Eg. <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="file:test.properties" /> </bean> <bean id="dbconnectionFactory" class="com.test.Test"> <property name="username" value="${username}" /> <property name="password" value="${password}" /> </bean> Can I

Spring Boot: Profiles ignored in PropertySourcesPlaceholderConfigurer loaded file

泪湿孤枕 提交于 2019-12-11 03:52:15
问题 I have a library that is a Spring Boot project. The library has a library.yml file that contains dev and prod props for its configuration: library.yml --- spring: profiles: active: dev --- spring: profiles: dev env: dev --- spring: profiles: prod env: prod Another application uses this library and loads the props using: @Bean public static PropertySourcesPlaceholderConfigurer dataProperties() { PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new

Spring Boot bind @Value to Enum case insensitive

帅比萌擦擦* 提交于 2019-12-05 01:14:54
Enum public enum Property { A, AB, ABC; } Field @Value("${custom.property}") protected Property property; application.properties (lower case) custom.property=abc When I'm running application I have an error: Cannot convert value of type [java.lang.String] to required type [com.xxx.Property]: no matching editors or conversion strategy found. Whereas (upper case): custom.property=ABC Works fine. Is there a way to bind the value case insensitive? Like ABC , Abc , AbC , abc any pattern should work. NOTE: I saw this question - Spring 3.0 MVC binding Enums Case Sensitive but in my case I have over

Spring @Value TypeMismatchException:Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'

ぐ巨炮叔叔 提交于 2019-12-03 08:17:30
问题 I want to use the @Value annotation to inject a Double property such as: @Service public class MyService { @Value("${item.priceFactor}") private Double priceFactor = 0.1; // ... and using Spring property placeholder (Properties files): item.priceFactor=0.1 I get Exception: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'; nested exception is java.lang.NumberFormatException: For input string: "${item

Spring @Value is not resolving to value from property file

拜拜、爱过 提交于 2019-12-03 05:28:20
问题 I've had this working in some other project before, I am just re-doing the same thing but for some reason it's not working. The Spring @Value is not reading from property file, but instead it's taking the value literally AppConfig.java @Component public class AppConfig { @Value("${key.value1}") private String value; public String getValue() { return value; } } applicationContext.xml: <context:component-scan base-package="com.test.config" /> <context:annotation-config /> <bean id=