You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by asookazian2 <as...@gmail.com> on 2014/04/16 17:51:51 UTC

Unable to find resource using Spring ClassPathXmlApplicationContext

Code:

import org.springframework.context.support.ClassPathXmlApplicationContext;
...
ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext("workflow-ws-context.xml");

also tried:

ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext("WEB-INF/classes/workflow-ws-context.xml");

getting following in karaf.log when starting bundle:

Caused by: java.io.FileNotFoundException: class path resource
[WEB-INF/classes/workflow-ws-context.xml] cannot be opened because it does
not exist
	at
org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
	at
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
	... 84 more

I have the following in pom.xml:

<Bundle-ClassPath>., WEB-INF/classes
, ...
</Bundle-ClassPath>

and the file exists in the mega bundle WAR (WAB) when I explode it after
'mvn clean install'.  It exists as
<root>/WEB-INF/classes/workflow-ws-context.xml.

Please advise how to fix/proceed.  thx.



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by Achim Nierbeck <bc...@googlemail.com>.
Just some quick hints from my side. You are using pax web samples in
version 4.0.0-snapshot those won't work with karaf 3. You'll need to use
the 3.1 samples available from maven central if you have karaf 3.0.1. And
make sure the required features are installed. That would be spring-dm and
some version of spring. All available with karaf already.

Regards, Achim

sent from mobile device
Am 17.04.2014 01:33 schrieb "asookazian2" <as...@gmail.com>:

> just realized those code samples from org.ops4j.pax.web don't use this type
> of code:
>
> ClassPathXmlApplicationContext context = new
> ClassPathXmlApplicationContext("WEB-INF/classes/workflow-ws-context.xml");
>
> and it's not able to resolve that reference to that resource.  how to
> handle?
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032819.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
just realized those code samples from org.ops4j.pax.web don't use this type
of code:

ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext("WEB-INF/classes/workflow-ws-context.xml");

and it's not able to resolve that reference to that resource.  how to
handle?



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032819.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
Ok the problem was that some of the dependencies in the osgi spring pom were
defined as provided, etc. so none of the libs were making it into the
web-inf/lib dir, now they're there.

I am able to install and activate the war-spring.war (OSGi spring version). 
I am able to navigate to http://localhost:8181/war-spring.

However, i see the following in the log:

Caused by: org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException:
Failed to convert property value of type 'java.lang.String' to required type
'java.lang.Class' for property 'contextClass'; nested exception is
java.lang.IllegalArgumentException: Cannot find class
[org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext]
	at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)[254:org.ops4j.pax.web.samples.spring:4.0.0.SNAPSHOT]
	at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:62)[254:org.ops4j.pax.web.samples.spring:4.0.0.SNAPSHOT]
	at
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:125)[254:org.ops4j.pax.web.samples.spring:4.0.0.SNAPSHOT]
	at
javax.servlet.GenericServlet.init(GenericServlet.java:161)[73:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0]
	at
org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:532)[79:org.eclipse.jetty.aggregate.jetty-all-server:8.1.14.v20131031]
	... 33 more

To use Spring-DM Web, install:
spring-osgi-web.jar - Spring-DM web support
spring-osgi-web-extender.jar - Spring-DM web extender

http://docs.spring.io/osgi/docs/1.1.0-m2/reference/html/web.html

are these the correct jar's for
org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext?

how to fix this?  thx.



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032818.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
Made the bundle-classpath match for both but there is no WEB-INF/lib
directory being created by mvn during mvn install...



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032817.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
war-spring/pom.xml:

<Bundle-Classpath>
                            WEB-INF/classes,
                            WEB-INF/lib/aopalliance-1.0.jar,
                            WEB-INF/lib/commons-logging-1.1.1.jar,
                            WEB-INF/lib/spring-aop-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-asm-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-beans-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-context-3.1.0.RELEASE.jar,
                           
WEB-INF/lib/spring-context-support-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-core-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-expression-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-jdbc-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-orm-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-tx-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-web-3.1.0.RELEASE.jar,
                            WEB-INF/lib/spring-webmvc-3.1.0.RELEASE.jar
                        </Bundle-Classpath>

war-spring-osgi/pom.xml:

<Bundle-Classpath>
                            WEB-INF/classes
                        </Bundle-Classpath>



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032816.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
there is no WEB-INF/lib with these spring dependencies in the WAR/WAB.  So
which other bundles/projects are required for installation in karaf to test
this spring osgi karaf web app???



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032814.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
manifest.mf from WAR:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven Bundle Plugin
Built-By: arbisookazian
Build-Jdk: 1.7.0_51
Bnd-LastModified: 1397686489449
Bundle-Classpath: WEB-INF/classes
Bundle-Description: Pax Web Samples
Bundle-DocURL: http://www.ops4j.org/
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.html
Bundle-ManifestVersion: 2
Bundle-Name: OPS4J Pax Web - Samples - OSGi Spring War sample
Bundle-SymbolicName: org.ops4j.pax.web.samples.spring
Bundle-Vendor: OPS4J - Open Participation Software for Java
Bundle-Version: 4.0.0.SNAPSHOT
Export-Package: org.ops4j.pax.web.samples.spring.controller;uses:="jav
 ax.servlet.http,org.springframework.web.servlet,org.springframework.w
 eb.servlet.mvc";version="4.0.0.SNAPSHOT"
Import-Package: org.springframework.web.servlet;version="[3.1,4)",java
 x.servlet.http;resolution:=optional,org.springframework.web.servlet.m
 vc;resolution:=optional;version="[3.1,4)",org.springframework.web.ser
 vlet.view;version="[3.1,4)",org.springframework.osgi.web.context.supp
 ort
Tool: Bnd-2.1.0.20130426-122213
Web-ContextPath: war-spring



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032813.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
ok setting JAVA_HOME to installation path for JDK 7 fixed that problem.

now i successfully did 'mvn clean install' for the spring osgi pom and
getting following on startup in karaf 3.0.0:

admin@NextGate> install
file:"/Users/arbisookazian/Documents/osgi/org.ops4j.pax.web/samples/war-spring-osgi/target/war-spring.war"
Bundle ID: 247
admin@NextGate> start 247
Error executing command: Error executing command on bundles:
	Unable to execute command on bundle 247: Unresolved constraint in bundle
org.ops4j.pax.web.samples.spring [247]: Unable to resolve 247.0: missing
requirement [247.0] osgi.wiring.package;
(&(osgi.wiring.package=org.springframework.web.servlet)(version>=3.1.0)(!(version>=4.0.0)))



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032812.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
Fails with 3.0.5 and 3.2.1 as well.  Looks like mvn is using 1.6 JDK to
compile.  Not having any problem with my work project builds however.

NextGates-MacBook-Pro:helloworld-hs arbisookazian$ mvn -version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9;
2014-02-14T09:37:52-08:00)
Maven home: /Users/arbisookazian/Downloads/apache-maven-3.2.1
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"

also, i don't seem to have a JAVA_HOME set in ~/.bash_profile, maybe i can
set that to JDK 7 path....



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032811.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
NextGates-MacBook-Pro:helloworld-hs arbisookazian$ mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032810.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by Achim Nierbeck <bc...@googlemail.com>.
Looks a lot like it is mavens related, could you please use maven 3.0.x.
The project is still built with that version and proven to work with that
version.

Regards, Achim

sent from mobile device
Am 16.04.2014 21:54 schrieb "asookazian2" <as...@gmail.com>:

> Same error on multiple builds:
>
> org.ops4j.pax.web/samples/helloworld-hs
> org.ops4j.pax.web/samples/war-spring
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032808.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
Same error on multiple builds:

org.ops4j.pax.web/samples/helloworld-hs
org.ops4j.pax.web/samples/war-spring



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032808.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/war-spring-osgi

I'm trying to build and test this sample project but it's failing:

[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to
/Users/arbisookazian/Documents/osgi/org.ops4j.pax.web/samples/war-spring-osgi/target/classes
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 1:01.725s
[INFO] Finished at: Wed Apr 16 12:47:17 PDT 2014
[INFO] Final Memory: 12M/81M
[INFO]
------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)
on project war-spring-osgi: Fatal error compiling: invalid target release:
1.7 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please
read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException





--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032807.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by Achim Nierbeck <bc...@googlemail.com>.
Even though exploded wars work, those are very tricky.
Did you try it the way the samples works, with a spring feature and
spring-dm feature installed?

regards, Achim


2014-04-21 19:17 GMT+02:00 asookazian2 <as...@gmail.com>:

> I've tried deploying as an exploded WAR into the karaf deploy directory but
> that doesn't work either...
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032887.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>

Software Architect / Project Manager / Scrum Master

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by Achim Nierbeck <bc...@googlemail.com>.
Did you work yourself through the samples provided by Pax Web?
Take for example the war-spring-osgi sample.[1]
It is used in the following integration test for Karaf. [2]
For this sample to work you need to have spring and spring-dm installed as
feature first.
BTW. for your convenience I linked the 3.1.x samples which will also work
with latest Karaf 3.0.1.

a reference to a file path won't work since all bundles are usually stored
in some cache directory, this is different to the usual web containers.

regards, Achim


[1] -
https://github.com/ops4j/org.ops4j.pax.web/tree/pax-web-3.1.x/samples/war-spring-osgi
[2] -
https://github.com/ops4j/org.ops4j.pax.web/blob/pax-web-3.1.x/pax-web-itest-karaf/src/test/java/org/ops4j/pax/web/itest/karaf/SpringOsgiKarafTest.java


2014-04-21 19:22 GMT+02:00 asookazian2 <as...@gmail.com>:

> I tried absolute file path and file name and that doesn't work either.
>
> Please advise how to resolve this, taking too long....
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032889.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>

Software Architect / Project Manager / Scrum Master

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
This seems to work (this is a public static synchronized method in class
MyClass):

ClassLoader cl = Thread.currentThread().getContextClassLoader();
	       
//Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
	       
Thread.currentThread().setContextClassLoader(MyClass.class.getClassLoader());
	        ClassPathXmlApplicationContext context;
	        try {
	            context = new
ClassPathXmlApplicationContext("workflow-ws-context.xml");
	        }
	        finally {
	            Thread.currentThread().setContextClassLoader(cl);
	        }



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032893.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
I tried absolute file path and file name and that doesn't work either.

Please advise how to resolve this, taking too long....



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032889.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Unable to find resource using Spring ClassPathXmlApplicationContext

Posted by asookazian2 <as...@gmail.com>.
I've tried deploying as an exploded WAR into the karaf deploy directory but
that doesn't work either...



--
View this message in context: http://karaf.922171.n3.nabble.com/Unable-to-find-resource-using-Spring-ClassPathXmlApplicationContext-tp4032805p4032887.html
Sent from the Karaf - User mailing list archive at Nabble.com.