We are using artesia 3rd party product for our project and it is deployed in JBOSS EAP6.4, I want to use spring boot in our project and when I write sample REST webservices I am able to access the REST web service via URL.
As per the documentation of our product if we need to customize the project we need to write our custom war by specifying below two JBOSS files inside META-INF folder
jboss-all.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss umlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="artesia.ear" />
</jboss-deployment-dependencies>
</jboss>
so our custom logic should begin after successful start of artesia.ear.
our jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<sub-deployment>
<dependencies>
<module name="deploy" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Above deploy module contains all jars necessary for the project to run.
When I follow the same and created the war without spring in it, it was successful and there are no issues, we are able to use to customize war.
Now I want to do the same in Spring-boot 1.4.1 application, where my spring boot app should start after artesia.ear starts successfully and apart from spring jars my spring-boot app should use jars from module.xml.
I have placed the above two xml's inside META-INF of spring boot application but it is failing when deployed in JBOSS EAP6.4
Below is the error that I get
jboss-server.log
What I need to do to use same for my spring-boot app
EDIT 1:
I tried by placing both jboss files under WEB-INF folder of spring-boot application but still the facing the same issue
We need to make sure that META-INF and WEB-INF folders are lying side by side instead of keeping META-INF folder inside classes folder of WEB-INF which is where default spring-boot META-INF folder resides.
We are using JBOSS 5.1.0.GA and spring integration framework. We are placing the configuration files under the conf directory of the JBOSS to read them from the classpath. But now we are told that we should move all the configuration files from the conf directory to the WEB-INF directory of the war file. Everything was working fine When we placed the files under conf directory.
<bean id="xyz" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:CustomerService/property-files/*.properties</value>
</list>
</property>
</bean>
But when we move the configuration files from conf directory to WEB-INF directory by making the following changes we are getting the Exceptionjava.io.FileNotFoundException.
<bean id="xyz" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>/WEB-INF/CustomerService/property-files/*.properties</value>
</list>
</property>
</bean>
The exception details:
java.io.FileNotFoundException: URL [jndi:/localhost/pqawdTestWebApp/WEB-INF/CustomerService/spring-integration/Jobs/] cannot be resolved to absolute file path because it does not reside in the file system: jndi:/localhost/pqawdTestWebApp/WEB-INF/CustomerService/spring-integration/Jobs/
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:205)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
at org.springframework.core.io.UrlResource.getFile(UrlResource.java:169)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:526)
Anybody has idea on what to do?
Place them in the class path (by some build means).
/WEB-INF/classes/CustomerService/property-files/*.properties
WEB-INF directory path will not be available as classpath in the standalone Spring project. So, I have moved the configuration files to src/resources folder to import them without any hassle.
I am developing a JavaSE application using JPA. Unfortunately, I get null after calling:
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
Below you will find:
A snippet of my code that invokes EntityManagerFactory and unexpectedly returns null
My persistence.xml file
My project structure
Snippet of my code:
public class Main {
private static final String PERSISTENCE_UNIT_NAME = "MeineJpaPU";
private static EntityManagerFactory factory;
public static void main(String[] args) {
// I get null on this line!!!
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
// do stuff with entity manager
...
}
}
My persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="MeineJpaPU" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>path.to.package.server.Todo</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/test"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.password" value="postgres"/>
</properties>
</persistence-unit>
</persistence>
My project structure:
You must move persistence.xml file to an appropriate location.
More specifically, add META-INF/persistence.xml file to the root of a source folder.
In this case, the following is an appropriate location: src\main\java\META-INF\persistence.xml
Here are the details:
(taken from the JPA spec)
A persistence.xml file defines a persistence unit. The persistence.xml
file is located in the META-INF directory of the root of the
persistence unit.
The root of the persistence unit is the key here.
If you are a non-Java EE app
The jar file or directory whose META-INF directory contains the
persistence.xml file is termed the root of the persistence unit.
If you are in a Java EE app, the following are valid
In Java EE environments, the root of a persistence unit must be one of
the following:
an EJB-JAR file
the WEB-INF/classes directory of a WAR file[80]
a jar file in the WEB-INF/lib directory of a WAR file
a jar file in the EAR library directory
an application client jar file
Quick advice:
check if persistence.xml is in your classpath
check if hibernate provider is in your classpath
With using JPA in standalone application (outside of JavaEE), a persistence provider needs to be specified somewhere. This can be done in two ways that I know of:
either add provider element into the persistence unit: <provider>org.hibernate.ejb.HibernatePersistence</provider> (as described in correct answer by Chris here: https://stackoverflow.com/a/1285436/784594)
or provider for interface javax.persistence.spi.PersistenceProvider must be specified as a service, see here: http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html (this is usually included when you include hibernate,or another JPA implementation, into your classpath
In my case, I found out that due to maven misconfiguration, hibernate-entitymanager.jar was not included as a dependency, even if it was a transient dependency of other module.
See also answers here: No Persistence provider for EntityManager named
So in my case, everything was in the class path, but I had to add
Class c = Class.forName("org.eclipse.persistence.jpa.PersistenceProvider");
I think this caused the PersistenceProvider to register itself with the javax classes. I have had to do something similar for JDBC drivers in the past as well.
I recently upgraded NB 8.1 to 8.2 and suddenly faced this problem and spent 2 days breaking my head to resolve. Up to 8.1, removing processorpath (mentioned above by others) worked. With 8.2, the problem persisted.
Finally, I found that the eclipselink.jar is missing in the default library of EclipseLink (JPA 2.1). I added the file to the definition of the library and voila - it started working!
If you don't want to move your META-INF folder (maybe because that's where your IDE created it and you don't want to confuse it), and if you are using Maven, you can tell Maven where to look for META-INF using the <resources>tag. See: http://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html
In your case:
<build>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
</build>
Dont give JPA dependency explicity
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
Thanks,
Rahul
I'm writing a java Application for Tomcat 7.
I have a bean configuration for a class that creates a log file and appends information to it.
now the question is how can I know the tomcat log directory path in bean configuration.
for now I have the following bean:
<bean id="foo_logger" class="com.bar.LoggerBean">
<!-- <property name="logPath" value="/path/DWHEventGenerator.log"/> -->
<property name="logPath" value="/var/lib/tomcat7/logs/mylog.log"/>
<property name="logLevel" value="ALL"/> <!-- ALL, FINE/R/ST, INFO, SEVERE, WARNING, OFF -->
</bean>
what i'd like to do is instead of specify /var/log/tomcat7/log, is to specify some variable that will indicate the actual path of the logs directory of tomcat. is that possible ?
thank you.
The simplest approach would be to use catalina.base from the system properties in the logPath property value
<property name="logPath" value="${catalina.base}/logs/mylog.log"/>
This property will be set by Tomcat's launch script (catalina.sh/catalina.bat) so will be available for use when Spring loads the application context file.
I tried to have an upload option for my spring web app, and I add following resolver
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="500000"></property>
</bean>
I also included two jar files in my WEB-INF/lib folder: commons-fileupload-1.3.jar and commons-io-2.4.jar. But when I run it, it still reports the error:
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:2398)
java.lang.Class.getDeclaredConstructors(Class.java:1838)
WHat am I still missing? I checked that the FileItemFactory is indeed in my Web App Library.
Thanks
It seems I put some of the jar files to my tomcat common shared lib folder, and some to my WEB-INF/lib folder. I moved everything to my webapp lib folder, and now it works fine.