We can add project dependency jars (like spring jars, logging etc) in shared library, can we add shared project jars (like one that communicate with Database) in shared library?
Scenario:
I have these projects
WebApp
WebAppEAR
CommonDB
I am using IBM Websphere server, hibernate, spring mvc
I added all spring, hibernate jars including CommonDB.jar in Websphere shared library. WebApp Application is running successfully with spring controllers but when my application try to hit DB it throws exception.
Caused by: java.lang.IllegalStateException:
Actually WebApp is not loading <bean> DataSource. DataSource class is located in CommonDB project.
When I include CommonDB.jar in Deployment assembly of EAR WebApp runs successfully and fetches data from DB.
I want to exclude CommonDB.jar from Deployment assembly and only want to add it in shared library.
Adding jars in shared library will work. Try figuring out which beans are not initialized and add them in Spring file to initialize. Also check other bean properties for dependency.
Related
I actually want to know what exactly happens during WAR packaging of a spring boot application using Maven. My specific interest would be to know whether the embedded tomcat dependency will be included or not while packaging app as WAR.
Also, If we have some tomcat config properties defined in application.properties and deploy the WAR file to external Tomcat which config will be taken into account while running the application? Like the config properties defined in server.xml of Tomcat server or the properties defined in application.properties?
My specific interest would be to know whether the embedded tomcat dependency will be included or not while packaging app as WAR
This is covered in the Spring Boot reference documentation:
If you use the Spring Boot build tools, marking the embedded servlet container dependency as provided produces an executable war file with the provided dependencies packaged in a lib-provided directory. This means that, in addition to being deployable to a servlet container, you can also run your application by using java -jar on the command line.
When you deploy a war to Tomcat, the configuration in server.xml is used rather than the server- and Tomcat-related configuration in application.properties. Specifically, none of your application's server.* properties will have any effect.
Below my project structure
I have multiple modules in one parent maven project.
Many of above modules can also run as independent project including some of them as Openshift applications. These are spring boot applications
Now I want to add one more module as Spring boot web application on Openshift that uses Spring web in build tomcat.
Also I have multiple property files which are specific to environment and I load them as Configmaps on Openshift.
Now when I am trying to deploy the new web application, it is not able to use the Configmaps. It error says property file not found. I am sure this is because the Configmaps are outside of the tomcat and application.
Can I have any work around as I don't want to put those property files in the war while building but should get added when I deploy or start the pod on Openshift.
In short I want something like I can put configmaps as files into the class path spring boot web application that uses in built tomcat.
Mount the ConfigMap-s as volumes at some path and then configure Spring Boot as described here.
Application structure description: Ear application with ejb module (.jar), jboss-seam (.jar) and war module (.war).
I have a StartupAction.class (seam component) annotated with org.jboss.seam.annotations.Startup. During application deployment I need to get the resource from application.war module root (application.war/pages/page.xhtml) and WEB-INF/classes (application.war/WEB-INF/classes/file.properties)
Jboss 4.2
Thread.currentThread().getContextClassLoader().getResourceAsStream("file.properties") would fetch the file from application.war/WEB-INF/classes/file.properties.
Jboss 7.1.1
Code from above doesn't work with Jboss 7.
I know that the class loading changed but I can't figure it out how to get into application.war in jboss 7.
Is it possible to do this? Are there any example of this?
Thanks in advance.
As mentioned by #BalusC, you will not be able to read a properties file that is embedded in a web module from any other modules (EJB or otherwise) that are packaged in your EAR.
The fact that this works in JBoss 4.x is a consequence of it providing backwards compatibility for even earlier versions of JBoss. Additional configuration is required in JBoss 4.x in order for it to use specification compliant class loading. JBoss 7.x and newer use specification compliant class loading by default.
If your properties file contains external configuration that is intended to be accessible after deployment then you might consider the approach described in How to put an external file in the classpath.
However, if it is effectively static data then you should package the properties file in a jar module and place it in the the lib directory of your EAR.
In jboss7, you have a classloader for each subdeploy.
In your case, Thread.currentThread().getContextClassLoader() will return the classloader of the current deployment.
To fix your problem, you could try this:
SomeRandomClassContainedInsideTheWAR.class.getClassLoader()
Check this guide to learn more about JBoss7 ClassLoader
https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7
maven module spring application.
1 module is a spring mvc application, another is a non-web but spring managed application.
In my project root, I have:
/src/main/conf
This folder contains my non-web managed spring xml configuration. I added this folder to my class path in intellij.
IntelliJ doesn't pickup the file correctly, meaning I don't get code completion or anything (allot of the names etc. are in bold red i.e. intellij is telling me something is wrong). Can this be fixed somehow?
I have kept my spring mvc config file inside its module (not in the conf folder) because the code completion doesn't work and it's a pain to work with without the IDE helping. But it makes managing things during deployment harder.
In both of my spring config files (for the web app and non-web app), I have my dataSource settings hard-coded in the file, I want to extract this somehow into a properties file, how can I do this?
1 - You can have different spring configuration files all in the same folder, just you need to use different names form them. So, I would use src/main/resources instead to create a new folder in the maven project structure. You will avoid problems.
2- Datasource in both files? why? If you have already two spring configuration files, I would create a third one (application-context-dao.xml) and share the dataSource. How to move properties to a configuration file? See.
I am maintaining following structure for my project
Web - Web Project
Model - EJB Project
Persistence - Java project having data classes and their mapping for Hibernate
Pokuri - EAR Project
As we know we can give jar file to hibernate configuration to load mapping information from jar. As I deploy EAR on to server I just want to build SessionFactory from mapping files in Persistence jar. But I am unable to get the path for that jar. Plz guide me to get the jar path. Or suggest me the best way to build SessionFactory and bind the same to a JNDI name.
Take a look at this thread - it may contain useful information.
Also, make sure your jar is mapped in your application.xml as an ejb module.