Spring cant find properties file in Tomcat classpath. - java

I have Spring configured to look up a conf/database.properties file to load some configuration.
This works well outside Tomcat, and in Junit tests, but in Tomcat, it never load. Below the images of this problem.
Configurations:
And:
The properties file in project folder:
The parameters to run Tomcat inside Eclipse:
The temp0 Tomcat Folder, where is all the files being generated Ok:
The Tomcat error log:
https://gist.github.com/4060538

I solved the problem. I think I was using spring in the wrong way.
I changed the follow:
In the library I'm importing/referencing, I removed the line where was importing database.properties file.
I created a spring.xml in my main web app, where in this file I imported the database.properties file and the other app-context.xml files I need to reference.
I think Spring spring don't load properties file outside of the jar. You need to load properties file locally in you main application, and so, references another spring-context.xml files needed.

Related

How to specify a profile when deploying a Spring boot war file to Tomcat?

At the moment, all my properties are defined in the file src/main/resources/application.properties. However, I would like to have properties files relating to different profiles in the src/main/resources/config folder, and I want to be able to choose any of them. such as:
application-DEV.properties
application-TEST.properties
application-SERVER1.properties
So, the question is how to select these properties. If I was compiling to a jar file, I could do that easily by specifiying the profile when running the jar file, but here I just copy the generated war file to a Tomcat webapps directory.
Well, I've found a way to do that. In the conf directory of Tomcat, add this line to the file catalina.properties there.
spring.profiles.active=<YOUR_PROFILE>
Replace <YOUR_PROFILE> here of course with your profile's name. For example if you are using application-TEST.properties, it would be the following.
spring.profiles.active=TEST
You can define Jvm Argument -Dspring.profiles.active=<PROFILE> on server start up file (.bat/.sh) depending on your environment.

Spring Boot configuration from application.properties

I see that the values in application context are not getting picked up when the Spring Boot project is war file and runs on an external Tomcat.
How do I resolve this issue?
Example - server.port=8096 but the port when loaded is still 8080
You may need to move the properties file outside of your project. The application.properties under src/main/resources will remain but referencing the external properties file. For e.g.
spring.config.location=./tomcatfolder/external-application.properties

Update xml file in JAR with weblogic deployment plan

I have a java application(not a EJB, not a MDB, it has a class implements ApplicationLifecycleListener). I build this java application into a jar file then create an EAR file include this jar, deploy the EAR file on a weblogic server, it works perfectly fine.
Now I want to use weblogic deployment plan to update some of the values in a configuration file which located inside the jar file. I generated the deployment plan, but it does not recognize my configuration XML file. I tried manually add it to the deployment plan, and use the deployment plan to redeploy this application. But nothing is updated.
I have read some examples of updating ejbs, but did not find anything about update a JAR's configuration inside an EAR, can anyone please give me example or send leave a link on how to properly use weblogic deployment plan to update a configuration file inside a JAR which is packed within an EAR file. Thanks.
You probably have to place the XML file in a jar file with same name under the same path as the original and use this jar in AppFileOverrides.

Hibernate cannot find Persistence.xml

I have a web app i created with Hibernate in Netbeans. I can't run my app because of classpath issues. It can't find my persistence.xml file. this is the project's folder structure in Netbeans:
Web pages
- META-INF
- persistence.xml
- Web-INF
Source packages
- <default package>
- persistence.xml
com.company.me
- java source files
= (One of the files contains the main() method that i am using to run
the app. I am not running the project as web app but rather as normal app using the main() method as entry point)
You can see that persistence.xml is in two places. I just put them there to test if it will find them. I read from some other posts that the persistence.xml must be in src/main/resources, I have tried to create that folder structure but it didn't work and put the META-INF/persistence.xml there but it didn't work.
I have also tried to create the same folder structure on the file system but it didn't work as well.
Put it in WEB-INF/classes. That's the root of the classpath for a web application.

Glassfish 3.1.2 lib/jar referral from ejb.jar issue

I have been working on migrating our code base onto Glassfish 3.1.2 using Java 7. I have been struck with this issue, where the deployment of EAR fails. I have an EAR, having modules, ejb.jar, couple of war files, along with lib directory having jar files to be shared across other modules within the EAR.
The issue is that ejb.jar refers to some spring bean definitions in lib/abc.jar file and is unable to find the spring file. The structure is like this:
EAR
ejb.jar (some spring files in here refer to lib spring file like, xyz.xml importing spring/abc.context.xml)
couple of war projects.
lib/lot of jar files (one of the jar here contains the spring file being referred from ejb.jar, note the file is inside directory inside the jar, like spring/abc-context.xml)
But the ejb jar cant load the bean definitions from lib/.jar
I have tried using the Manifest.MF inside the ejb.jar to refer to lib/abc.jar, but with no luck....
Not sure if there is some sort of problem with new GF 3.1.2, why its not able to respect the Manifest file. Any help will be much appreciated!
It looks like the JVM doesnt like the manually edited Manifest file and my guess is that windows is adding something like a carriage return etc. I managed to get it working by using the ant to generate the manifest file instead.
Thanks and hope that helps someone.

Categories

Resources