Deployment of simple Spring web application on OSGI with Karaf - spring
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
Related
Tomcat 7 Gets Errors During Startup of Java Project
I have a Java project which was working perfectly before. Now I'm getting the errors below. The server startup is successful but the services do not work. Java version of the project is 8 and I use Tomcat 7 server. web.xml: <?xml version="1.0" encoding="UTF-8"?> <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_2_5.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>ProjectName</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>ServiceNameRest</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ServiceNameRest</servlet-name> <url-pattern>/projectName/*</url-pattern> </servlet-mapping> <listener> <listener-class>...contextlistener.OCServletContextListener</listener-class> </listener> </web-app> 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>ProjectName</groupId> <artifactId>ProjectName</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <finalName>ProjectName2</finalName> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <inherited>true</inherited> <configuration> <source>1.8</source> <target>1.8</target> <webXml>src\main\webapp\WEB-INF\web.xml</webXml> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.3.0</version> <configuration> <failOnMissingWebXml>true</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.ow2.asm</groupId> <artifactId>asm</artifactId> <version>5.0.3</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-bundle</artifactId> <version>1.19</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.19</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.3</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20140107</version> </dependency> <dependency> <groupId>nz.ac.waikato.cms.weka</groupId> <artifactId>weka-stable</artifactId> <version>3.8.0</version> </dependency> <dependency> <groupId>nz.ac.waikato.cms.weka</groupId> <artifactId>LibSVM</artifactId> <version>1.0.4</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.9</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.17</version> </dependency> <dependency> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.asynchttpclient</groupId> <artifactId>async-http-client</artifactId> <version>2.2.0</version> </dependency> </dependencies> </project> Error Log: Haz 27, 2020 2:16:29 PM org.apache.catalina.core.ApplicationContext log SEVERE: StandardWrapper.Throwable java.lang.IllegalArgumentException at jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:170) at jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:153) at jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:424) at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138) at com.sun.jersey.core.spi.scanning.JarFileScanner.scan(JarFileScanner.java:97) at com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner$1.f(WebAppResourcesScanner.java:94) at com.sun.jersey.core.util.Closing.f(Closing.java:71) at com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:92) at com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:79) at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80) at com.sun.jersey.api.core.servlet.WebAppResourceConfig.init(WebAppResourceConfig.java:102) at com.sun.jersey.api.core.servlet.WebAppResourceConfig.(WebAppResourceConfig.java:89) at com.sun.jersey.api.core.servlet.WebAppResourceConfig.(WebAppResourceConfig.java:74) at com.sun.jersey.spi.container.servlet.WebComponent.getWebAppResourceConfig(WebComponent.java:668) at com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:435) at com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:602) at com.sun.jersey.spi.container.servlet.WebServletConfig.getDefaultResourceConfig(WebServletConfig.java:87) at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:699) at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674) at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205) at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1269) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1182) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Haz 27, 2020 2:16:29 PM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet [Jersey Web Application] in web application [/DocumentClassifier] threw load() exception java.lang.IllegalArgumentException at jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:170) at jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:153) at jersey.repackaged.org.objectweb.asm.ClassReader.(ClassReader.java:424) at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138) at com.sun.jersey.core.spi.scanning.JarFileScanner.scan(JarFileScanner.java:97) at com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner$1.f(WebAppResourcesScanner.java:94) at com.sun.jersey.core.util.Closing.f(Closing.java:71) at com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:92) at com.sun.jersey.spi.scanning.servlet.WebAppResourcesScanner.scan(WebAppResourcesScanner.java:79) at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80) at com.sun.jersey.api.core.servlet.WebAppResourceConfig.init(WebAppResourceConfig.java:102) at com.sun.jersey.api.core.servlet.WebAppResourceConfig.(WebAppResourceConfig.java:89) at com.sun.jersey.api.core.servlet.WebAppResourceConfig.(WebAppResourceConfig.java:74) at com.sun.jersey.spi.container.servlet.WebComponent.getWebAppResourceConfig(WebComponent.java:668) at com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:435) at com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:602) at com.sun.jersey.spi.container.servlet.WebServletConfig.getDefaultResourceConfig(WebServletConfig.java:87) at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:699) at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674) at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205) at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1269) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1182) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
spring2 annotation has not rendered
I am new to startup a Java with Spring 2.5.5 project. But have some problem that the Spring annotation has not been resolved. I means my JSP shows the spring annotation directly, like this: ${msg} [ \target\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>com.demo.spring</groupId> <artifactId>HelloWorldSpringWeb</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>HelloWorldSpringWeb Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <jdk.version>1.6</jdk.version> <spring.version>2.5.6</spring.version> <jstl.version>1.2</jstl.version> <servletapi.version>2.5</servletapi.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- Spring MVC framework --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <!-- JSTL --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <!-- for compile only, your container should have this --> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>${servletapi.version}</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>HelloWorldSpringWeb</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> </configuration> </plugin> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.2.11.v20150529</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <webApp> <contextPath>/spring2</contextPath> </webApp> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> <wtpversion>2.0</wtpversion> <wtpContextName>spring2</wtpContextName> </configuration> </plugin> </plugins> </build> </project> [ \WEB-INF\web.xml ] <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> </web-app> [ \WEB-INF\mvc-dispatcher-servlet.xml ] <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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <bean name="/welcome.htm" class="com.demo.spring.HelloWorldController" /> <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> <context:component-scan base-package="com.demo.spring" /> </beans> [ com.demo.spring.HelloWorldController.java ] package com.demo.spring; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; #RequestMapping("/welcome") public class HelloWorldController { #RequestMapping(method = RequestMethod.GET) public ModelAndView helloWorld(){ ModelAndView model = new ModelAndView("index"); model.addObject("msg", "hello world"); return model; } } [ \WEB-INF\pages\index.jsp ] <%# taglib prefix="spring" uri="http://www.springframework.org/tags"%> <html> <body> <h2>Hello World!!!</h2> <h2>${msg}</h2> </body> </html> To access the controller, use this URL: http://127.0.0.1:8080/HelloWorldSpringWeb/welcome.htm Finally, output on web browser like this: Hello World!!! ${msg} As you see, ${msg} is not rendered. What's wrong? Thank you very much.
After my investigation, I should correct my question to: "Spring 2.5.6 EL has not been resolved". And now I know that I can add this statement on every pages those has EL expression inside: <%# page isELIgnored="false" %> Yes it can solve my problem. But I don't want to add this statement in too many pages in my project. I find that it is caused by isELIgnored is default to "true" if web.xml is equal or lower than version 2.3. So that I need to add this code to set isELIgnored to true globally: <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <el-ignored>false</el-ignored> </jsp-property-group> </jsp-config> But no luck. The EL is still hasn't been resolved. Someone can help? Thanks a lot.
Struts JSP page does not display correctly, it shows the unparsed source code in browser
I use Tomcat 8 and Struts 1.3.10 when i execute my application http://127.0.0.1:8080/appli/welcome.jsp i have this in my browser <%# taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <%# taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %> <%# taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean" %> <%# taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <%# taglib uri="http://struts.apache.org/tags-logic-el" prefix="logic" %> "> "> Message in the console: 2016-01-21 15:20:39 DEBUG ModuleUtils:171 - Get module name for path /generic/authentification/Login.do 2016-01-21 15:20:39 DEBUG ModuleUtils:196 - Module name found: default 2016-01-21 15:20:39 DEBUG RequestProcessor:161 - Processing a 'GET' for path '/generic/authentification/Login' 2016-01-21 15:20:39 DEBUG TilesRequestProcessor:265 - uri=/WEB-INF/jsp/generic/tiles/template_blank.jsp doInclude=false 2016-01-21 15:25:12 DEBUG ApplicationFilter:59 - Requested path : '/accueil.jsp' - method : GET 2016-01-21 15:25:12 DEBUG ApplicationFilter:63 - Acces refusé 2016-01-21 15:25:12 DEBUG ModuleUtils:171 - Get module name for path /generic/authentification/Login.do 2016-01-21 15:25:12 DEBUG ModuleUtils:196 - Module name found: default 2016-01-21 15:25:12 DEBUG RequestProcessor:161 - Processing a 'GET' for path '/generic/authentification/Login' 2016-01-21 15:25:12 DEBUG TilesRequestProcessor:265 - uri=/WEB-INF/jsp/generic/tiles/template_blank.jsp doInclude=false what's wrong ? I forget to configure some things ? My 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.project</groupId> <artifactId>appli</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>appli</name> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> <!-- Applicatif --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.0.7.Final</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-core</artifactId> <version>1.3.10</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-extras</artifactId> <version>1.3.10</version> </dependency> <!-- JSP TLD --> <dependency> <groupId>net.fckeditor</groupId> <artifactId>java-core</artifactId> <version>2.6</version> </dependency> <!-- <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-taglib</artifactId> <version>1.3.10</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-el</artifactId> <version>1.3.10</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-tiles</artifactId> <version>1.3.10</version> </dependency> <!-- Birt --> <dependency> <groupId>org.eclipse.birt.runtime</groupId> <artifactId>org.eclipse.birt.runtime</artifactId> <version>4.3.0</version> <exclusions> <exclusion> <artifactId>org.apache.poi</artifactId> <groupId>org.eclipse.birt.runtime</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.9</version> </dependency> <!-- Divers --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>com.novell.ldap</groupId> <artifactId>jldap</artifactId> <version>2009-10-07</version> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> <version>1.5.5</version> </dependency> </dependencies> <build> <finalName>apex</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> <archive> <manifestEntries> <Specification-Title>J2EE Servlet</Specification-Title> <Specification-Version>2.5</Specification-Version> <Specification-Vendor>Sun Microsystems</Specification-Vendor> <Implementation-Title>${pom.name}</Implementation-Title> <Implementation-Version>${pom.version}</Implementation-Version> <Implementation-Vendor>${pom.organization.name}</Implementation-Vendor> <Built-By>me</Built-By> <Implementation-URL>${pom.url}</Implementation-URL> </manifestEntries> </archive> <compilerArguments> <endorseddirs>${endorsed.dir}</endorseddirs> </compilerArguments> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.6</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>7.0</version> <type>jar</type> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> welcome.jsp: <%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%# taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Login Example</title> </head> <body> <html:form action="/login" focus="userName"> Username : <html:text property="userName" /> <br> Password : <html:password property="password" /> <br> <html:submit value="login" /> </html:form> </body> </html> web.xml when i comment the two line all it work but when i uncomment this line i have the pb <?xml version="1.0" encoding="ISO-8859-1"?> <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_2_5.xsd" version="2.5"> <display-name>Struts Blank Application</display-name> <!-- Standard Action Servlet Configuration --> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <!-- <init-param> <param-name>chainConfig</param-name> <param-value>org/apache/struts/tiles/chain-config.xml</param-value> </init-param> --> <load-on-startup>2</load-on-startup> </servlet> <!-- Standard Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- <servlet-mapping> --> <!-- <servlet-name>jsp</servlet-name> --> <!-- <url-pattern>/javascript/generic/messages.js</url-pattern> --> <!-- </servlet-mapping> --> <!-- <servlet-mapping> --> <!-- <servlet-name>jsp</servlet-name> --> <!-- <url-pattern>*.css</url-pattern> --> <!-- </servlet-mapping> --> <!-- The Usual Welcome File List --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
If you have unparsed code in jsp page means that JSP engine didn't run at all You have overridden web configuration in web.xml. because you didn't post it with the question I can't tell you where it's wrong. May be you have incorrectly mapped an action servlet to /*. This is just standard configuration <!-- Standard Action Servlet Configuration --> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <!-- Standard Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
Could not open JPA EntityManager for transaction in spring
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.
How to enable Apache Tuscany SDO with OSGi container? [classloader issue]
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>