properties-file

Spring Boot integration tests doesn't read properties files

喜夏-厌秋 提交于 2019-12-03 16:20:32
I would like to create integration test in which Spring Boot will read a value from .properties file using @Value annotation. But every time I'm running test my assertion fails because Spring is unable to read the value: org.junit.ComparisonFailure: Expected :works! Actual :${test} My test: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {WebTests.ConfigurationClass.class, WebTests.ClassToTest.class}) public class WebTests { @Configuration @ActiveProfiles("test") static class ConfigurationClass {} @Component static class ClassToTest{ @Value("${test}") private String

How would I specify a Hibernate “@Pattern” annotation using a regular expression from a .properties file or database

只愿长相守 提交于 2019-12-03 14:23:08
Situation : I would like to perform Hibernate Validation based upon user properties (to allow different validation rules for input based upon a user's account data) - I think it must be possible to use a .properties file to specify a particular regular expression, but I can't figure out what is wrong: My current method of specifying a validation regex pulls that regex from a constant in a particular interface file (to keep everything together) and plugs it in as a constant in an @Pattern() annotation for each variable - e.g. for the variable workPhone : @Column(name = "WORK_PHONE") @NotEmpty

Expose <property-placeholder> properties to the Spring Environment

牧云@^-^@ 提交于 2019-12-03 13:51:16
问题 I have a properties file that I'm registering with Spring through XML, using the property-placeholder element: <context:property-placeholder location="classpath:foo.properties" /> I can access properties using @Value annotations, e.g. @Value("${prefs.key}") private String prefValue; but I also need to access properties via the Spring Environment, e.g. @Autowired private Environment env; public String getValue(String key) { return env.getProperty(key); } getValue() here always returns null ,

Include A Properties File With A Jar File

亡梦爱人 提交于 2019-12-03 07:17:20
I've written a small application. I've put the database specific information in a properties file. db.url=jdbc:mysql://localhost:3306/librarydb db.user=root db.passwd=pas$w0rd When I build the application to get the executable jar file, the properties file gets included inside. The whole purpose of putting those information in a properties file is to allow the user to change those but this is making it impossible. How can I include a properties file with the jar file not in it? Kinda like you do with AppSettings file in .NET applications. I'm very new to Java so I'd appreciate if you could

Configure Java EE 6 for dev/QA/prod

こ雲淡風輕ζ 提交于 2019-12-03 04:01:35
I have a Java EE 6 app that I build with Maven, code in NetBeans 7 and deploy on GlassFish 3.1.2. As I near completion, I find myself deploying demo builds. The problem is that I don't have any dead easy way to build for different environment such as dev, QA, demo, prod, etc. For some stuff, I've been using a Java class with a bunch of static getters that return values based on the value of an environment constant. But this doesn't help me with conditionally setting javax.faces.PROJECT_STAGE (web.xml) database credentials (glassfish-resources.xml) mail servers (glassfish-resources.xml) JPA

adding comment in .properties files

两盒软妹~` 提交于 2019-12-02 23:22:44
By using following block of code in build.xml file <propertyfile file="default.properties" comment="Default properties"> <entry key="source.dir" value="1" /> <entry key="dir.publish" value="1" /> <entry key="dir.publish.html" value="1" /> </propertyfile> I am able to generate default.properties file with following file contents source.dir=1 dir.publish=1 dir.publish.html=1 I want to know how can I add my comments in the generated file? E.g. the generated properties should have the following content: # Default Configuration source.dir=1 dir.publish=1 # Source Configuration dir.publish.html=1

How to get all properties files in a package and update the key values using java?

人盡茶涼 提交于 2019-12-02 14:12:32
I tried a lot, but was unable to find a solution. | |--src/main/resouces | |-updatePropertiesFile.java |-xyz_en_US.properties |-xyz_en_AF.properties |-xyz_en_AE.properties This is my project structure. I have a updatePropertiesFile class, to update a key for all the properties file. I have around 200 properties file. So what I need is that, I need to write a method to update a particular key in all these properties file. Manual change is not that practically. I need to write an application which does this funtionality. I tried using resoucebundle mechanism. But using resource bundle, we can

How to resolve placeholder in properties file with values from another properties file in spring boot application

浪子不回头ぞ 提交于 2019-12-02 08:33:47
问题 My spring boot application has below properties files. src/main/resources/config/DEV/env.properties mail.server=dev.mail.domain src/main/resources/config/QA/env.properties mail.server=qa.mail.domain src/main/resources/config/common/env.properties mail.url=${mail.server}/endpoint Is it possible to load "common/env.properties" so that it's placeholders will be resolved using the given environment specific properties file. For DEV environment, we want the placeholders in "common/env.properties"

Java web app: Tomcat and configuration files .properties

六眼飞鱼酱① 提交于 2019-12-02 08:30:47
问题 I have a java web app with Tomcat as servlet container. I would to use different configuration files for different build configurations, i.e. 1) demo.properties 2) real.properties 3) test.properties in which I would to specify the database name, db user and password (now for the db I use JNDI resource configuration in app context.xml ), if send mail should be enabled or not (now I have two methods whose content I have to comment or not according to the purpose), some css image paths and some

How to resolve placeholder in properties file with values from another properties file in spring boot application

拟墨画扇 提交于 2019-12-02 08:06:15
My spring boot application has below properties files. src/main/resources/config/DEV/env.properties mail.server=dev.mail.domain src/main/resources/config/QA/env.properties mail.server=qa.mail.domain src/main/resources/config/common/env.properties mail.url=${mail.server}/endpoint Is it possible to load "common/env.properties" so that it's placeholders will be resolved using the given environment specific properties file. For DEV environment, we want the placeholders in "common/env.properties" to be resolved using values from "DEV/env.properties". There are answers about how to load multiple