How can I use an properties file inside JBOSS AS7 in Spring? - spring

I want to use somthing like this:
//#PropertySource("classpath:myconfig.properties")
My config file is in the deployments folder.
Remember:JBOSS AS7!!

In my case (in JB 7), I have the properties in an exploded war file under WEB-INF and they get picked up. I assume that you meant that the war file/folder was in the deployments folder.
and I use Spring 4

Related

Springboot application cannot find application.yml from external folder (#PropertySource)

I am trying to write a spring boot app (for tomcat), which has an application.yml file for configuration.
My goal is to search for this yml file FIRST from the resources, and if it is not there, then SECONDLY from the tomcat's conf folder.
My code, which is not working:
#SpringBootApplication
#ComponentScan(basePackages = "com.my.app")
#EnableConfigurationProperties
#PropertySource(ignoreResourceNotFound=true,value={"classpath:application.yml","file:${catalina.base}/conf/application.yml"})
public class MyApplication extends SpringBootServletInitializer {
...
}
I want this, because if I work on my Eclipse, and want to use Tomcat server from Eclipse. In this case I want to use the resources folder. But if I build the war then I skip the yml file from it with the maven war plugin, and deploy it manually to Tomcat, I want to use the tomcat's folder.
if I leave the yml file on the resources folder of the project, it works
if I delete the yml file from the resources, and place to the ${catalina.base}/conf folder (which is the embedded tomcat for eclipse, I know it), it doesn't work
if I delete the #PropertySource annotation, and leave the yml file in resources, it works
So my app works only if the yml file on the resources folder, even if I add or remove the #PropertySource annotation.
How should I set to search for the resources folder for first time, and if there is no yml file, then search for the second option, which is the tomcat folder?

How to externalize i18n properties files in spring-boot applications

I’ve succeed to externalize my spring-boot configuration file (application.properties) in a config folder when I run my spring-boot application as a unix service with the help of the official spring documentation https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
I have also some i18n messages.properties files in my src/main/resources that I would like to externalize in the same config folder but I failed to do it. I’ve tried a lot of things, like playing with spring.messages.basename but unfortunately, it doesn’t work.
I’m using the latest version of spring-boot, and use auto configure mode with the default i18n properties name messages.
What am I missing??? thanks for your help.
Just a few notes:
classpath:message - will always lookup embeded message_xxx files
classpath:/message and classpath:message are equivalent
file:message - will lookup jar's external current directory e.g. ./message_en.properties <- this is what you want
file:/message - you have to put your message files to root "/" to make it work
use notation file:config/message if you need to put in config folder together with your
./config/application.properties
I think you need a leading slash.
Try: spring.messages.basename=classpath:/config/messages
I think, resource bundle is default to classpath. So there's no need to append it. just go straight to your folder location from classpath.
Try this: **assuming your config is inside static folder
spring.messages.basename=static/config/messages

serving files from a spring boot war file

I've followed the guide here for turning a "hello, world" level Spring Boot app to a war file. I can run this war like a jar and it will return the simple template.
What I don't understand is why I can't access a main.css file I've created. I've placed it in the resources directory under "static/css/main.css" and according to the docs here Spring Boot will automatically server files under "resources", "static", "public", and "META-INF/resources". However, when I build my war file and run it I can't query those files in the browser (like http://localhost:8080/static/css/main.css). Have a missed a step? If I peek into the created war file I see the "static" directory in "WEBINF/classes" right beside the "templates" directory and the directory holding my application.
Files in src/main/resources/static are served from / so you don't need static in the path. You CSS file should be available from http://localhost:8080/css/main.css

Custom tomcat context.xml for Spring App

I have a Spring App, and I would like change the session cookie path. I know this can be done in the server's context.xml file, but I don't have permission to edit that file on my server. Is there another way to do this, maybe by adding another context.xml file somewhere?
Btw, I added a context.xml file to my project's META-INF folder, but it didn't work.
Bundle your context.xml with your war file.

Do i need a context.xml file to deploy spring webapp to tomcat

I am new to Tomcat, so I apologize if this is a dumb question. I have created a spring mvc webapp that currently runs locally using the maven-jetty-plugin.
I can successfully create the WAR file. I would like to deploy the WAR file into a tomcat6 instance. However, I am not sure if I need to create a context.xml file for tomcat? And if I do, where would I place the file in my spring webapp? My current directory structure looks like this:
src
|
|-main
| |-java
|-resource
| |-META-INF
|-webapp
| |-WEB-INF
|-web.xml
The context.xml file is used to configure application specific instructions for your container (tomcat). For instance, you can define JNDI resources, loggers, valves, etc. See Context Container for more details.
By default, Tomcat will auto-generate a default context.xml for your war if you do not specify one yourself and store it within its own configuration files in /conf/[enginename]/[hostname]/[context-root].xml
If you want to include it as part of your war, you can place it in /META-INF/context.xml within your war.
No, you don't. The context.xml file is optional, and by no means required by Spring.
context.xml is used to configure Tomcat itself. The defaults are sensible, there's no need to override them unless you have a good reason.

Resources