I try to use Apache CXF in Apache ServiceMix with SDO. SDOs are provided with Apache Tuscany SDO implementation.
Here is the dependency map:
My osgi-bundle exposes a web service, bundle depends on SDO.
CXF system bundle depends on SDO too.
I installed Apache Tuscany SDO bundle stack as follows:
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-api-r2.1/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-impl/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-lib/1.1.1
osgi:install -s mvn:org.apache.tuscany.sdo/tuscany-sdo-tools/1.1.1
Start levels are:
...
tuscany-sdo-api-r2.1 28
tuscany-sdo-impl 28
tuscany-sdo-lib 28
tuscany-sdo-tools 28
Apache CXF Bundle Jar (2.4.6) 30
camel-cxf (2.8.5) 50
camel-cxf-transport (2.8.5) 50
...
MyApplication 60
Whe I restart the server I get the folowwing exception printed:
karaf#root> Exception in thread "SpringOsgiExtenderThread-4" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iws': Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ExceptionInInitializerError
at org.apache.cxf.sdo.SDODataBinding.initialize(SDODataBinding.java:128)
at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:444)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:685)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:507)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:205)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:157)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:203)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:433)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:322)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:239)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:509)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 14 more
Caused by: java.lang.NullPointerException
at org.apache.tuscany.sdo.api.SDOUtil.<clinit>(SDOUtil.java:48)
... 35 more
As I can see in the source code of org.apache.tuscany.sdo.api.SDOUtil.java (link):
46 public final class SDOUtil
47 {
48 protected static SDOHelper defaultSDOHelper = ((HelperProviderBase)HelperProvider.INSTANCE).sdoHelper();
49 ...
SDOUtil class from tuscany-sdo-api-r2.1 depends on a helper class commonj.sdo.impl.HelperProvider.java.
Source code for HelperProvider.java (link)
64 static {
65 // initialize the default instance using this class's classloader
66 // set to null if none could be located (implies no default implementation)
67 HelperProvider provider;
68 try {
69 provider = getInstance(HelperProvider.class.getClassLoader());
70 } catch (NoHelperProviderException e) {
71 provider = null;
72 }
73 INSTANCE = provider;
74 }
This means that getInstance() method does not work properly.
How to make SDOHelper to get initialized correctly in an OSGi contained?
UPDATE
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- Generated by Apache ServiceMix Archetype -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.bssys</groupId>
<artifactId>eg-smx-osgi-bundle</artifactId>
<packaging>bundle</packaging>
<version>1.0-SNAPSHOT</version>
<name>Apache ServiceMix :: Camel OSGi Bundle</name>
<properties>
<camel.version>2.8.3</camel.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<!-- CXF SDO -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-databinding-sdo</artifactId>
<version>2.4.6</version>
</dependency>
<!-- Apache tuscany SDO -->
<dependency>
<groupId>org.apache.tuscany.sdo</groupId>
<artifactId>tuscany-sdo-api-r2.1</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sdo</groupId>
<artifactId>tuscany-sdo-impl</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sdo</groupId>
<artifactId>tuscany-sdo-lib</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sdo</groupId>
<artifactId>tuscany-sdo-tools</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.6</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*,org.apache.camel.osgi</Import-Package>
<Private-Package>com.bssys</Private-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
camel-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Apache ServiceMix Archetype -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://camel.apache.org/schema/osgi"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/osgi http://camel.apache.org/schema/osgi/camel-osgi.xsd
http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
">
<osgi:camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="timer://myTimer?fixedRate=true&period=10000"/>
<bean ref="myTransform" method="transform"/>
<to uri="log:ExampleRouter"/>
</route>
</osgi:camelContext>
<bean id="myTransform" class="com.bssys.MyTransform">
<property name="prefix" value="${prefix}"/>
</bean>
<osgix:cm-properties id="preProps" persistent-id="com.bssys">
<prop key="prefix">MyTransform</prop>
</osgix:cm-properties>
<ctx:property-placeholder properties-ref="preProps" />
<!-- HTTP Endpoint -->
<jaxws:endpoint xmlns:iws="http://www.bssys.com/SMEV/IWS/1"
id="iws" address="/iws1"
serviceName="iws:IWSExport_BaseImportIWSHttpService"
endpointName="iws:IWSExport_BaseImportIWSHttpPort"
implementor="com.bssys.smev.iws._1.BaseImportIWSImpl">
<!--
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
-->
</jaxws:endpoint>
<!--
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route/>
</camelContext>
-->
</beans>
Related
I am completely new to Spring and Hibernate. I am having some difficulty getting Spring and Hibernate to cooperate so that my Spring configuration returns a Session object from the SessionFactory object.
In particular, I have followed the tutorial at: https://www.baeldung.com/hibernate-5-spring. This tutorial is for configuring Spring and Hibernate for the H2 database. However, I am currently configuring Spring and Hibernate for Oracle 12.2. I have reflected the changes in the configuration files.
Just like the aforementioned site suggests, I have written a Maven project with all the required dependencies. Moreover, I am configuring Hibernate 5 with an XML-based configuration.
Please find the code below:
Here is the Spring - Hibernate configuration file:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.test">
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="debug">true</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp2.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#localhost:1521:ORCL"/>
<property name="username" value="sa"/>
<property name="password" value="sa"/>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
Here is the Java code that I am using to try and secure the Hibernate Session object:
#Autowired
private SessionFactory sessionFactory;
public Session getSession()
{
Session session = null;
try
{
session = sessionFactory.getCurrentSession();
if(session != null)
{
System.out.println("Session is VALID.");
}
else
{
System.out.println("Session is INVALID.");
}
}
catch(IllegalStateException e)
{
System.out.println("getSession: Illegal State Exception: " + e.getMessage());
}
catch(Exception e)
{
System.out.println("getSession: Exception: " + e.getMessage());
}
return session;
}
Here is the project pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>Flow</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Flow</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.springframework.version>5.0.2.RELEASE</org.springframework.version>
<org.springframework.data.version>1.10.6.RELEASE</org.springframework.data.version>
<org.springframework.security.version>4.2.1.RELEASE</org.springframework.security.version>
<hibernate.version>5.2.10.Final</hibernate.version>
<hibernatesearch.version>5.8.2.Final</hibernatesearch.version>
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
<jta.version>1.1</jta.version>
<hsqldb.version>2.3.4</hsqldb.version>
<oracle.version>12.2.0.1</oracle.version>
<commons-lang3.version>3.5</commons-lang3.version>
</properties>
<repositories>
<repository>
<id>maven.oracle.com</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven.oracle.com</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven.oracle.com</id>
<url>https://maven.oracle.com</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- persistence -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${org.springframework.data.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>${jta.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>${tomcat-dbcp.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>${oracle.version}</version>
</dependency>
</dependencies>
<build>
<finalName>Flows</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
What I am expecting to receive is a Session object; however, when I run my code, the variable session i returns null. Any help would be greatly appreciated. Thanks!
The hibernate property hibernate.current_session_context_class defines how SessionFactory retrieve the current Session. When using LocalSessionFactoryBean to build SessionFactory , by default it will set to SpringSessionContext which basically means Spring will mange the session for you.
So in most case , you don't need to get the session by calling sessionFactory.getCurrentSession(). Simply use #PersistenceContext to inject and use the Session:
#PersistenceContext
private Session session;
Am new to Spring Rest Docs... Have a preexisting codebase what was written in Spring MVC (not Spring Boot).
Some excerpts from my pom.xml looks as following:
<properties>
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>1.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*Documentation.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
<sourceDocumentName>index.adoc</sourceDocumentName>
<attributes>
<snippets>${snippetsDirectory}</snippets>
</attributes>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/static/docs</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/generated-docs</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Have a sample web service (using SpringMVC) which issues a simple GET request:
package com.myapp.rest.controllers;
#Controller
#RequestMapping("/v2")
public class MyController {
#RequestMapping(value="users/{userId}",method=RequestMethod.GET)
public #ResponseBody Object getUserDetails(#PathVariable String userId){
Object response=null;
UserDAO dao = UserDAO.getInstance();
response=dao.getUser(userId);
return response;
}
}
Calling this using curl:
curl -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/myapp/v2/users/123
Returns the following payload:
{
"device": "D045453",
"userId": "123",
"userDetails":
[
{
"propertyName": "Position",
"propertyValue": "Manager"
},
{
"propertyName": "Salary",
"propertyValue": "120000"
},
{
"propertyName": "Name",
"propertyValue": "John Smith"
}
]
}
Have setup my MockMvc test case like this:
WebAppConfiguration
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = "classpath:**/mvc-dispatcher-servlet.xml")
public class MyControllerDocumentation {
private static final String USER_ID = "123";
#Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
#Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
#Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation)).build();
}
#Test
public void getUserDetails() throws Exception {
this.mockMvc.perform(get("/v2/users/{userId}", USER_ID)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("device").isNotEmpty())
.andDo(document("{class-name}/{method-name}"));
}
}
There's no applicationContext.xml anywhere just the mvc-dispatcher-servlet.xml (which resides in src/main/webapp/WEB-INF):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<context:component-scan base-package="com.myapp.rest.controllers" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
I start tomcat (because I already have a previous war file containing this rest call in $CATALINA_HOME/webapps) and when try to build the war file:
mvn clean install
This is what comes up in Surefire Reports:
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.638 sec <<< FAILURE!
getUserDetails(com.myapp.rest.controllers.MyControllerDocumentation) Time elapsed: 0.2 sec <<< FAILURE!
java.lang.AssertionError: Status expected:<200> but was:<404>
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54)
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81)
at org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:665)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:171)
at om.myapp.rest.controllers.MyControllerDocumentation.getUserDetails(MyControllerDocumentation.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
Question(s):
How can I obtain a simple HTTP 200 from my unit test? Is this a config issue?
Inside the:
.andDo(document("{class-name}/{method-name}"));
How do I setup it to document the various properties (key / value pairs) located in the response JSON payload using Spring Rest Docs?
Am thinking that I do not need to have tomcat running (with a previous war file)?
Sorry, have never used Spring Rest Docs and just wishing someone could point me in the right direction...
I'm trying to run a simple Spring Web application on OSGI - Karaf 3.0.1 with no results.
On my fresh Karaf instance I've installed following features:
spring 4.0.2.RELEASE_1
spring-web 4.0.2.RELEASE_1
pax-http 3.0.1
pax-war 3.0.1
war 3.0.1
pax-jetty 8.1.14.v20131031
Here is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>co.chudy.kairos</groupId>
<artifactId>spring-web</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring-web Maven Webapp</name>
<properties>
<spring.version>4.0.2.RELEASE</spring.version>
<jdk.version>1.7</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-web</artifactId>
<version>1.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>spring-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>war</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>jar</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Vendor>Michal Chudy</Bundle-Vendor>
<Export-Package>co.chudy.kairos.spring</Export-Package>
<Web-ContextPath>kairos</Web-ContextPath>
<Bundle-ClassPath>.,WEB-INF/classes,{maven-dependencies}</Bundle-ClassPath>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>HelloWorldSpring</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
mvc-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean name="/helloWorld.do" class="co.chudy.kairos.spring.Home"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
And I've tried lots of things and searched a lot and still I'm getting stacktraces about missing context classes. I've tried different web.xml and servlet configurations and each time it was the same error - missing class. I also tried different versions of spring features.
Here is the stacktrace: (full karaf log)
2014-07-26 15:49:28,119 | INFO | raf-3.0.1/deploy | fileinstall | 11 - org.apache.felix.fileinstall - 3.2.8 | Updated D:\apache-karaf-3.0.1\deploy\spring-web.war
2014-07-26 15:49:28,439 | INFO | raf-3.0.1/deploy | HttpServiceFactoryImpl | 93 - org.ops4j.pax.web.pax-web-runtime - 3.1.0 | Binding bundle: [spring-web [210]] to http service
2014-07-26 15:49:28,445 | INFO | raf-3.0.1/deploy | fileinstall | 11 - org.apache.felix.fileinstall - 3.2.8 | Started bundle: file:/D:/apache-karaf-3.0.1/deploy/spring-web.war
2014-07-26 15:49:28,502 | INFO | pool-13-thread-1 | AppHttpContext{spring-web - 210} | 84 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.14.v20131031 | Initializing Spring FrameworkServlet 'mvc-dispatcher'
2014-07-26 15:49:28,502 | INFO | pool-13-thread-1 | DispatcherServlet | 212 - org.apache.servicemix.bundles.spring-webmvc - 4.0.2.RELEASE_1 | FrameworkServlet 'mvc-dispatcher': initialization started
2014-07-26 15:49:28,503 | INFO | pool-13-thread-1 | XmlWebApplicationContext | 207 - org.apache.servicemix.bundles.spring-context - 4.0.2.RELEASE_1 | Refreshing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Sat Jul 26 15:49:28 CEST 2014]; root of context hierarchy
2014-07-26 15:49:28,504 | INFO | pool-13-thread-1 | XmlBeanDefinitionReader | 205 - org.apache.servicemix.bundles.spring-beans - 4.0.2.RELEASE_1 | Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
2014-07-26 15:49:28,526 | ERROR | pool-13-thread-1 | DispatcherServlet | 212 - org.apache.servicemix.bundles.spring-webmvc - 4.0.2.RELEASE_1 | Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.InternalResourceViewResolver] for bean with name 'viewResolver' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.InternalResourceViewResolver not found by org.ops4j.pax.web.pax-web-jetty [94]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:959)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:680)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)[207:org.apache.servicemix.bundles.spring-context:4.0.2.RELEASE_1]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)[207:org.apache.servicemix.bundles.spring-context:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at javax.servlet.GenericServlet.init(GenericServlet.java:161)[79:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0]
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:532)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:344)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:791)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doStart(HttpServiceContext.java:222)[94:org.ops4j.pax.web.pax-web-jetty:3.1.0]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl$1.start(JettyServerImpl.java:197)[94:org.ops4j.pax.web.pax-web-jetty:3.1.0]
at org.ops4j.pax.web.service.internal.HttpServiceStarted.end(HttpServiceStarted.java:1032)[93:org.ops4j.pax.web.pax-web-runtime:3.1.0]
at org.ops4j.pax.web.service.internal.HttpServiceProxy.end(HttpServiceProxy.java:422)[93:org.ops4j.pax.web.pax-web-runtime:3.1.0]
at org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC.end(RegisterWebAppVisitorWC.java:341)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.model.WebApp.accept(WebApp.java:678)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.register(WebAppPublisher.java:237)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:182)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:135)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:932)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:864)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:317)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)[karaf-org.osgi.core.jar:]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher.publish(WebAppPublisher.java:101)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebObserver.deploy(WebObserver.java:213)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebObserver$1.doStart(WebObserver.java:175)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.extender.SimpleExtension.start(SimpleExtension.java:58)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.extender.AbstractExtender$1.run(AbstractExtender.java:266)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_55]
at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_55]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)[:1.7.0_55]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)[:1.7.0_55]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_55]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_55]
at java.lang.Thread.run(Thread.java:745)[:1.7.0_55]
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.view.InternalResourceViewResolver not found by org.ops4j.pax.web.pax-web-jetty [94]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)[org.apache.felix.framework-4.2.1.jar:]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)[:1.7.0_55]
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1844)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:937)[org.apache.felix.framework-4.2.1.jar:]
at org.ops4j.pax.swissbox.core.BundleClassLoader.findClass(BundleClassLoader.java:176)[85:org.ops4j.pax.swissbox.core:1.6.0]
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)[:1.7.0_55]
at org.ops4j.pax.swissbox.core.BundleClassLoader.loadClass(BundleClassLoader.java:192)[85:org.ops4j.pax.swissbox.core:1.6.0]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)[:1.7.0_55]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:236)[203:org.apache.servicemix.bundles.spring-core:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:392)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
... 47 more
2014-07-26 15:49:28,528 | WARN | pool-13-thread-1 | AppHttpContext{spring-web - 210} | 84 - org.eclipse.jetty.aggregate.jetty-all-server - 8.1.14.v20131031 | unavailable
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.InternalResourceViewResolver] for bean with name 'viewResolver' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.InternalResourceViewResolver not found by org.ops4j.pax.web.pax-web-jetty [94]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:959)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:680)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)[207:org.apache.servicemix.bundles.spring-context:4.0.2.RELEASE_1]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)[207:org.apache.servicemix.bundles.spring-context:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)[212:org.apache.servicemix.bundles.spring-webmvc:4.0.2.RELEASE_1]
at javax.servlet.GenericServlet.init(GenericServlet.java:161)[79:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0]
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:532)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:344)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:791)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doStart(HttpServiceContext.java:222)[94:org.ops4j.pax.web.pax-web-jetty:3.1.0]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)[84:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl$1.start(JettyServerImpl.java:197)[94:org.ops4j.pax.web.pax-web-jetty:3.1.0]
at org.ops4j.pax.web.service.internal.HttpServiceStarted.end(HttpServiceStarted.java:1032)[93:org.ops4j.pax.web.pax-web-runtime:3.1.0]
at org.ops4j.pax.web.service.internal.HttpServiceProxy.end(HttpServiceProxy.java:422)[93:org.ops4j.pax.web.pax-web-runtime:3.1.0]
at org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC.end(RegisterWebAppVisitorWC.java:341)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.model.WebApp.accept(WebApp.java:678)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.register(WebAppPublisher.java:237)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:182)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:135)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:932)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:864)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:317)[karaf-org.osgi.core.jar:]
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)[karaf-org.osgi.core.jar:]
at org.ops4j.pax.web.extender.war.internal.WebAppPublisher.publish(WebAppPublisher.java:101)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebObserver.deploy(WebObserver.java:213)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.WebObserver$1.doStart(WebObserver.java:175)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.extender.SimpleExtension.start(SimpleExtension.java:58)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at org.ops4j.pax.web.extender.war.internal.extender.AbstractExtender$1.run(AbstractExtender.java:266)[136:org.ops4j.pax.web.pax-web-extender-war:3.1.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_55]
at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_55]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)[:1.7.0_55]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)[:1.7.0_55]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_55]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_55]
at java.lang.Thread.run(Thread.java:745)[:1.7.0_55]
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.view.InternalResourceViewResolver not found by org.ops4j.pax.web.pax-web-jetty [94]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)[org.apache.felix.framework-4.2.1.jar:]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)[:1.7.0_55]
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1844)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:937)[org.apache.felix.framework-4.2.1.jar:]
at org.ops4j.pax.swissbox.core.BundleClassLoader.findClass(BundleClassLoader.java:176)[85:org.ops4j.pax.swissbox.core:1.6.0]
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)[:1.7.0_55]
at org.ops4j.pax.swissbox.core.BundleClassLoader.loadClass(BundleClassLoader.java:192)[85:org.ops4j.pax.swissbox.core:1.6.0]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)[:1.7.0_55]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:236)[203:org.apache.servicemix.bundles.spring-core:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:392)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)[205:org.apache.servicemix.bundles.spring-beans:4.0.2.RELEASE_1]
... 47 more
But sometime the missing class was OsgiBundleXmlWebApplicationContext or ContextNamespaceHandler.
Any ideas what am I doing wrong?
You will need to install Spring-DM also and use the OsgiBundleXmlWebApplicationContext for it.
A Sample can be found here.
In Short you'll need to switch to the following in your web.xml:
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</init-param>
</servlet>
If it is ok for your to confine your Spring WebMVC setup to one bundle and only use services from other bundles, you can have a look at [1]. There is a recipe [2] on how to use Eclipse Equinox (OSGi), EclipseLink (JPA) and Spring WebMVC with Jetty 9.2 and JSP/JSTL.
[1] http://dentrassi.de/2014/11/14/osgi-ee-modular-web-applications/
[2] https://github.com/ctron/osgiee/tree/master/web5
Hi and thanks for read my problem.
I am writing a simple program to admin users, cars, payments.. in a garage. thhis is a maven project and i use spring and hibernate wiht sqlite.
I am geting this excetion when i try just to exetuce a basic test of my aplication
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:313)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clienteDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory Modelo.GenericDaoHibernate.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [spring-config.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:106)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:57)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory Modelo.GenericDaoHibernate.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [spring-config.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
... 40 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [spring-config.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 42 more
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:396)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:117)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1596)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1519)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1420)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 52 more
I let you here my pom here:
<groupId>abegondo.taller</groupId>
<artifactId>taller</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>taller</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Versions -->
<spring.version>3.2.3.RELEASE</spring.version>
<hibernate.version>4.3.0.Final</hibernate.version>
<junit.version>4.8.1</junit.version>
<sqlite.version>3.7.15-M1</sqlite.version>
<!-- Hibernate properties -->
<hibernate.show_sql>true</hibernate.show_sql>
<hibernate.format_sql>true</hibernate.format_sql>
<hibernate.use_sql_comments>true</hibernate.use_sql_comments>
<dataSource.url>jdbc:sqlite:taller</dataSource.url>
<testDataSource.url>jdbc:sqlite:taller</testDataSource.url>
</properties>
<repositories>
<repository>
<id>hibernatesqlite-maven</id>
<url>https://hibernate-sqlite.googlecode.com/svn/trunk/mavenrepo</url>
</repository>
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.0.RELEASE</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>${sqlite.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.4.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
<!-- Others -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>sqlite</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- JDBC driver properties -->
<jdbcDriver.groupId>org.xerial</jdbcDriver.groupId>
<jdbcDriver.artifactId>sqlite</jdbcDriver.artifactId>
<jdbcDriver.version>${sqlite.version}</jdbcDriver.version>
<jdbcDriver.className>org.sqlite.JDBC</jdbcDriver.className>
<!-- Data source properties -->
<dataSource.url>jdbc:sqlite:taller</dataSource.url>
<testDataSource.url>jdbc:sqlite:taller</testDataSource.url> <dataSource.createTablesScript>src/main/resources/CreateTables.sql</dataSource.createTablesScript>
<!-- Hibernate properties -->
<hibernate.dialect>Modelo.SQLiteDialect</hibernate.dialect>
</properties>
</profile>
</profiles>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>${jdbcDriver.groupId}</groupId>
<artifactId>${jdbcDriver.artifactId}</artifactId>
<version>${jdbcDriver.version}</version>
</dependency>
</dependencies>
<configuration>
<driver>${jdbcDriver.className}</driver>
<username>${dataSource.user}</username>
<password>${dataSource.password}</password>
<srcFiles>
<srcFile>${dataSource.createTablesScript}</srcFile>
</srcFiles>
</configuration>
<executions>
<!-- The default sql:execute creates the production db -->
<execution>
<id>default-cli</id>
<phase>process-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>${dataSource.url}</url>
</configuration>
</execution>
<execution>
<id>create-test-db</id>
<phase>process-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>${testDataSource.url}</url>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>es.udc.protoduction.Sprodion</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
</project>
my hibernate-conf.xml:
<hibernate-configuration>
<session-factory>
<!-- Show and print SQL on stdout -->
<property name="hibernate.show_sql">${hibernate.show_sql}</property>
<property name="hibernate.format_sql">${hibernate.format_sql}</property>
<property name="hibernate.use_sql_comments">${hibernate.use_sql_comments}</property>
<property name="hibernate.dialect">Modelo.SQLiteDialect</property>
<mapping class="Modelo.Entidades.Cliente"/>
<mapping class="Modelo.Entidades.Coche"/>
<mapping class="Modelo.Entidades.Factura"/>
<mapping class="Modelo.Entidades.LineaFactura"/>
<mapping class="Modelo.Entidades.Pieza"/>
</session-factory>
</hibernate-configuration>
My spring configuration:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd " >
<context:annotation-config/>
<context:component-scan base-package="Modelo"/>
<bean id="jdbcDataSource3" class="org.apache.commons.dbcp.BasicDataSource" destroy- method="close" lazy-init="true">
<property name="driverClassName" value="org.sqlite.JDBC" />
<property name="url" value="jdbc:sqlite:taller" />
<property name="initialSize" value="2" />
<property name="maxActive" value="20" />
<property name="maxIdle" value="5" />
<property name="poolPreparedStatements" value="true" />
</bean>
<!-- Hibernate Session Factory -->
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="jdbcDataSource3"/>
<property name="configLocation" value="hibernate-config.xml"/>
</bean>
<!-- Hibernate Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<!-- Activates annotation based transaction management -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
Any idea why can this exception be throwed?
Hi i solved this problem sorry for answer here late.
I had an annotation bad, I write the #Id in an Set field instead of the correct id of the entity
I am building a testing application with JPA Hibernate 4.1.7 and Spring 3.1.3 on top.
I am getting a NPE at jta causing JPA EntityManager to fail, here is the stack trace
DEBUG TestContext - Retrieved ApplicationContext for test class [class cvut.dp.foodtables.service.FoodServiceImplTest] from cache with key [[MergedContextConfiguration#61cc1457 testClass = FoodServiceImplTest, locations = '{classpath:/WEB-INF/context/applicationContext.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']].
DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'txManager'
DEBUG JpaTransactionManager - Creating new transaction with name [testSome]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
DEBUG SessionImpl - Opened session at timestamp: 13525989368
DEBUG TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
DEBUG AbstractEntityManagerImpl - Looking for a JTA transaction to join
WARN TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener#16f88474] to process 'before' execution of test method [public void cvut.dp.foodtables.service.FoodServiceImplTest.testSome()] for test instance [cvut.dp.foodtables.service.FoodServiceImplTest#3210a146]
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NullPointerException
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.startTransaction(TransactionalTestExecutionListener.java:514)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.startNewTransaction(TransactionalTestExecutionListener.java:272)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:165)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:358)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73)
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:115)
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)
at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1220)
at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:178)
at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:89)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:179)
at org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:445)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:366)
... 31 more
DEBUG DirtiesContextTestExecutionListener - After test method: context [[TestContext#5579d6f9 testClass = FoodServiceImplTest, testInstance = cvut.dp.foodtables.service.FoodServiceImplTest#3210a146, testMethod = testSome#FoodServiceImplTest, testException = org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NullPointerException, mergedContextConfiguration = [MergedContextConfiguration#61cc1457 testClass = FoodServiceImplTest, locations = '{classpath:/WEB-INF/context/applicationContext.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]], class dirties context [false], class mode [null], method dirties context [false].
DEBUG DirtiesContextTestExecutionListener - After test class: context [[TestContext#5579d6f9 testClass = FoodServiceImplTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration#61cc1457 testClass = FoodServiceImplTest, locations = '{classpath:/WEB-INF/context/applicationContext.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]], dirtiesContext [false].
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 11.134 sec <<< FAILURE!
I have googled the error to death and still can't find any solution.
Here is the test:
package cvut.dp.foodtables.service;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
public class FoodServiceImplTest extends BaseServiceTest
{
#Autowired
private FoodService foodService;
public FoodServiceImplTest()
{
super();
}
#Test
public void testSome()
{
Long id = foodService.addFood("test", 15, "test");
assertEquals(1, foodService.getAllFood().size());
}
}
Which extends
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = {
"classpath:/WEB-INF/context/applicationContext.xml"})
#TransactionConfiguration(defaultRollback=true, transactionManager="txManager")
#Transactional //extend the transactions to whole tests in order to rollback the tests
public class BaseServiceTest
{
public BaseServiceTest()
{
}
}
I presume the error to be somewhere in my configuration, so I won't post all of the sources here...
Here is my applicationContext.xml (edit: changed to 3.1.xds files, no change)
<!--<?xml version="1.0" encoding="UTF-8"?>-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xmlns:faces="http://www.springframework.org/schema/faces"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
http://www.springframework.org/schema/faces
http://www.springframework.org/schema/faces/spring-faces-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
default-autowire="byType"
>
<!-- Enable annotions -->
<context:annotation-config />
<context:component-scan base-package="cvut.dp.foodtables"/>
<!-- #Configurable -->
<context:spring-configured/>
<!-- Property files -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/properties/jdbc.properties</value>
<value>/WEB-INF/properties/jpa.properties</value>
</list>
</property>
</bean>
<!-- JDBC data source -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialSize" value="2" />
<property name="minIdle" value="2" />
</bean>
<!-- JPA settings -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="${jpa.platform}"/>
<property name="generateDdl" value="true"/>
<property name="showSql" value="true"/>
</bean>
</property>
<property name="packagesToScan" value="cvut.dp.foodtables" />
</bean>
<!-- Define transaction manager -->
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- #Transactional support-->
<tx:annotation-driven transaction-manager="txManager" />
</beans>
I don't have persistence.xml
jdbc.properties:
jdbc.driverClassName=org.hibernate.dialect.MySQLDialect
jdbc.url=jdbc:mysql://localhost:3306/FoodTables
jdbc.username=root
jpa.properties:
jpa.platform=org.hibernate.dialect.MySQLDialect
Here is web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- SPRING -->
<context-param>
<description>Spring config files</description>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/context/*.xml
</param-value>
</context-param>
<listener>
<description>Loads Spring on server start</description>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<description>Request -> thread association</description>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- SPRING END -->
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
And my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cvut.dp</groupId>
<artifactId>FoodTables</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>FoodTables</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-documentation</artifactId>
<version>3.6.0.Beta2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.8.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<groupId>org.hibernate.javax.persistence</groupId>
<type>jar</type>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
<testResource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>**/context/applicationContext*.xml</include>
<include>**/properties/*.properties</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The most googled up answer was that I should be setting hibernate.transaction.jta.platform property in persistance.xml, which I don't have. This is my first ever Java EE app and I really don't exactly know what I am doing yet. But this error is frustrating.
I had the same problem. The solution is to use default-autowire="byName" instead of "byType" in your xml configuration. If you have "byType" Spring automatically autowire also the property "jtaDataSource" in the LocalContainerEntityManagerFactoryBean with your definied datasource bean.
While jens answer is correct and solves your problem, i just wanted to add that you don't have to change the default-autowiring for this. You can also set that on every bean itself.
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
autowire="byName">
...
Now you still have byType-autowiring on all of your beans except "entityManagerFactory"
This is no password entry defined in your jdbc.projects.
<property name="password" value="${jdbc.password}"/>
It is better to create a standalone user/password for your projects, do not use root in your production.
Try adding a "META-INF/persistence.xml":
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="myUnit" transaction-type="RESOURCE_LOCAL">
</persistence-unit>
</persistence>
Putting a breakpoint at org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo line 91 (PersistenceUnitTransactionType getTransactionType()) might also help you determine why spring thinks you have a jta-datasource or transaction type.