I made a message.validation.properties file inside root/src/resources and my code below inside the spring-servlet.xml is not recognized.
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>src/resources/messages.validation</value>
</list>
</property>
</bean>
I have tried classpath:messages.validation, messages.validation but I only get the warning message
WARNING: ResourceBundle [src/resources/messages.validation] not found for MessageSource: Can't find bundle for base name src/resources/messages.validation, locale en_US
How can I locate this file? Note that I do not want to put it in another folder ie. WEB-INF/classes.
This depends on how you build your project, but in the end the message.validation.properties file should up on the classpath, ie. WEB-INF/classes. If it is directly in there, you would specify
<value>classpath:messages.validation</value>
I'll assume that your src folder is a source folder in your IDE. As such, anything under it will be compiled/copied so that it ends up in the classpath directory. As such, you should be using
<value>classpath:resources/messages.validation</value>
Again, if /src/resources is the source folder, then you need
<value>classpath:messages.validation</value>
You have to add the resource folder to the classpath so it can become accessible.
If you use Eclipse, right-click on project, select Properties. Then on the left side select "Java build path" and add you resource directory with "Add Class Folder".
Try this:
<value>classpath:messages.validation</value>
Related
I have a Spring Project where I am using bean configuration file
beans.xml.Inside the bean Configuration file, i have defined some properties for a PlaceHolder which refers to classPath...While the application is running, the properties are getting loaded from /unknownPath/Dev/Loc1/System.properties
Where
${BUS_ENV}=Dev
${LOCATION1}=Loc1
<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>classpath:${BUS_ENV}/lbsprocessor.properties</value>
</list>
</property>
<!-- Force system properties to override any deployed runtime properties -->
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
I didn't specify classpath while running my project in IDE
I don't have those files in my resource folder
There are around 65 such files exists(for various reasons) as Dev/Loc1/System.properties
I am not able to find from which location the properties are getting referred. Even after debugging, I couldn't find out what classpath refers to. Please help me with figuring out
If you are using eclipse IDE right click on your project select properties then select Java Build Path. On first tab Source there is one input named Default Output folder that value is your classpath. Check all your properties files are there in that path.
Referring to your point 2 problems might be in these line
<value>classpath:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>classpath:${BUS_ENV}/lbsprocessor.properties</value>
You are using classpath for file location which means these properties file have to be in the .war file at /Dev/Loc1/System.properties
If properties files are outside of project may be at system level you can access them like this
<value>file:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>file:${BUS_ENV}/lbsprocessor.properties</value>
eg:
<value>file:/home/testuser/system.properties</value>
I am using Mac OS ,in this we are storing the Configurations as a jar file under
/Library/Java/Extension.So java is directly referring classpath to that location by default.
I have the following problem. I have a jar archive with a spring application inside (pure spring with xml configuration, without spring-boot). Someone decided to move some properties to external file. Unfortunately, the path is hardcoded in xml context file, so it looks like this:
<bean id="placeholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:hardcoded/path/props.properties</value>
</list>
</property>
</bean>
Both xml context file and property file are inside the archive. The application works fine, however, I need to change (override) some properties from the hardcoded file. Unfortunately, I can't modify or compile new jar. I tried adding files with overriden properties to the classpath (with the same name) and also passing some properties as jvm args, but it didn't work. How can I replace/override this file from classpath without modifying the original java archive?
I would take a look at the PropertyOverrideConfigurer.
Property resource configurer that overrides bean property values in an
application context definition. It pushes values from a properties
file into bean definitions.
That should allow you to "push" your own values on top of the prior-loaded set.
I currently have a file, {project-name}/WebContent/WEB-INF/applicationContext.xml, that sets a sub directory into a bean file for further use.
<bean ....>
<property ...>
<value>WEB-INF/utilities</value>
</property>
</bean>
Changes are being made to have these files normally located in this sub directory added to the Java resource folder when the war is build (done with the pom file). I have tried setting the bean to use this path, but failing when trying to access files inside of it.
<bean ....>
<property ...>
<value>{project-name}/Java Resources/src</value>
</property>
</bean>
Is there a better option to reference the project path so applicationContext.xml can have visibility to the source folder?
Can the pom declare an alternate destination for resource files when building? If I can have the pom set the files to "WEB-INF/utilities" instead of defaulting to "Java Resources/src" that should be able to resolve my issue.
I have read questions regarding accessing files from the java resource directory, but those solutions require implementing java classes to read values from the included files; not setting the actual path location in a bean for use by other beans. Not sure the benefit of having a new class just to retrieve a directory name.
My requirement is similar to that of Reading reloadable xml file from external Tomcat directory
I need to place my hibernate xml and property file outside of the exploded war file ie, inside tomcat/my_folder
I am importing this xml and the property file through applicationcontext.xml using the below code.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:D:/my_folder/jdbc.properties" />
</bean>
<!-- Load Hibernate related configuration -->
<import resource="file:D:/my_folder/hibernate-context.xml" />
The import of these files works fine but i when i update these files, the changes are not reflecting unless i restart Tomcat.
I also made the reloadabale property as true in tomcat server's
context.xml. Also i added entries for these files in
WatchedResource tag. But nothing works as this checks for the files only within the exploded war.
Please help me resolving this issue.
As far as I have found, Maven cannot change the current working directory for every module build in a reactor build (to the module that is being built) because it is not possible in standard Java to change the current working directory. First of all, is this correct?
If yes, how can I make the following scenario work?
UPDATE: I have a some.properties file that is supposed to be on the classpath of the module being built (e.g. in src/main/resources) and it is being referred to in a Spring context file of a Maven Plugin, like this:
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<array>
<value>classpath:some.properties</value>
</array>
</property>
</bean>
The Maven Plugin is being executed in "process-test-resources" phase. Also, some.properties file has a property that refers to an external relative configurable path:
some.spring.config.dir=target/test-classes
Then, a few config files from this path are loaded in spring context files in the module being built, such as:
<property name="configLocation" value="file:${some.spring.config.dir}/cache.xml" />
This scenario works when I build the project from its pom.xml directory but not when I build it as part of a reactor build from a top level directory. Is there a way to get it working when running maven from any directory and also keep the path in my properties file (e.g. "target/test-classes") relative?
Two steps required:
Include resource filtering for configuration file: http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
in configuration file add basedir:
some.spring.config.dir=${basedir}/target/test-classes
In "target" directory "some.spring.config.dir" will be filled with full path.