well I'm runnning this code and it cant' find the springconfig4.xml file:
package com.nortal.pirs.test.independant;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test4 {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("/com/nortal/pirs/beans/springconfig4.xml");
BeanFactory factory = context;
Test3 instance = (Test3) factory.getBean("Test3");
instance.run();
}
}
I mean I was kind of expecting it not to work, because in Java it never works when you try to use a path that is not in your current package. However as many Spring tutorials I've seen, they all show this way of specifying the configuration file.
Now my springconfig4.xml is in my applications' src/com/nortal/pirs/beans folder. So how do I specify it so that it can be found here?
The current Test4 class is located in src/com/nortal/pirs/test/independant folder.
My stacktrace:
2012-12-09 06:16:15,734 [main] INFO org.springframework.context.support.AbstractApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#b24044e: startup date [Sun Dec 09 06:16:15 EET 2012]; root of context hierarchy
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/asm/ClassVisitor
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:121)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:168)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:167)
at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:195)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:128)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:527)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:441)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.nortal.pirs.test.independant.Test4.main(Test4.java:9)
Caused by: java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 10 more
My springconfig4.xml:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.nortal.pirs.businesslogic.logic"></context:component-scan>
<context:component-scan base-package="com.nortal.pirs.test.independant"></context:component-scan>
</beans>
Or is the problem somewhere else maybe?
Your stacktrace points this:
java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
You need to download the spring-asm-3.1.2.RELEASE.jar file from the maven repo (supposing that you are using spring 3.1.2) or if you are using maven, edit your pom.xml file and add the next lines:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
Also, this line:
ApplicationContext context = new ClassPathXmlApplicationContext("/com/nortal/pirs/beans/springconfig4.xml");
Has an error, the path must not start with a trailing /., so the path to the file becomes: "com/nortal/pirs/beans/springconfig4.xml".
The ClassPathResource javadoc states that it will be removed anyways:
Create a new ClassPathResource for ClassLoader usage. A leading slash
will be removed, as the ClassLoader resource access methods will not
accept it.
Exception says it is not finding a class, not Spring context xml
Caused by: java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
please add asm dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.asm</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
Add spring-asm-3.0.1.RELEASE.jar and spring-expression-3.0.1.RELEASE.jar.
java.lang.ClassNotFoundException: org.springframework.asm.ClassVisitor
Just add the spring-asm-3.1.2.RELEASE.jar file. Place it in your lib folder.
For the above problem as mentioned above these jars are missing namely 1.org.springframework.asm-3.0.1.RELEASE-A.jar
2.org.springframework.expression-3.0.1.RELEASE-A.jar
or
Add all the core Jars of Spring so that any new programmer can Run all basic level programs.
There is no need of below line in your program. insted of that you can use context insted of factory in the above program.
BeanFactory factory = context
We usually use ApplicationContext insted of BeanFactory.
Even if you use BeanFactory there will be no effect for the program.
Add the Jars which is shown in the Screen short and it will work
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to learn Spring in java. I am stuck at the beginning when i run the fist program.
i am trying to call the draw method of the Triangle class .
But i am seeing many errors.
In the DrawingApp.java class eclipse is showing some warning - ( The type XmlBeanFactory is deprecated ).
I am providing my implementation along with errors below.
Triangle.java
package org.hemant.spring;
public class Triangle {
public void draw(){
System.out.println("Triangle drawn");
}
}
DrawingApp.java
package org.hemant.spring;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class DrawingApp {
/**
* #param args
*/
public static void main(String[] args) {
BeanFactory factory = new XmlBeanFactory(new FileSystemResource("spring.xml"));
Triangle triangle = (Triangle)factory.getBean("Triangle.class");
triangle.draw();
}
}
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bean PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-bean-2.0.dtd">
<bean>
<bean id="triangle" class="org.hemant.spring.Triangle"/>
</bean>
Errors
Apr 16, 2016 12:33:45 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\Users\hemant001\workspace_mars_eclipse\spring tutorial\spring.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [C:\Users\hemant001\workspace_mars_eclipse\spring tutorial\spring.xml]; nested exception is java.io.FileNotFoundException: http://www.springframework.org/dtd/spring-bean-2.0.dtd
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefiniti ons(XmlBeanDefinitionReader.java:408)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init> (XmlBeanFactory.java:78)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init> (XmlBeanFactory.java:66)
at org.hemant.spring.DrawingApp.main(DrawingApp.java:17)
Caused by: java.io.FileNotFoundException: http://www.springframework.org/dtd/spring-bean-2.0.dtd
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
... 5 more
You should replace http://www.springframework.org/dtd/spring-bean-2.0.dtd with http://www.springframework.org/dtd/spring-beans-2.0.dtd (notice beans, not bean) in your spring.xml.
This:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bean PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-bean-2.0.dtd">
<bean>
<bean id="triangle" class="org.hemant.spring.Triangle"/>
</bean>
should be something like
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="triangle" class="org.hemant.spring.Triangle"/>
</beans>
Also, like mentioned in the comments, factory.getBean("Triangle.class"); should be factory.getBean("triangle");
For context, I'd rather do
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
...
ApplicationContext context = new ClassPathXmlApplicationContext(
"spring.xml"); // or FileSystemXmlApplicationContext, if .xml is not in class path
Triangle obj = (Triangle) context.getBean("triangle");
And why are you using version 2.0 of Spring (based on your dtd)? That's really old.
Please do not use XmlBeanFactory anymore, use the DefaultListableBeanFactory because it seperates the reader from the factory and represent a more clean OOD.
It is not realy a error, its a format-problem with the configuration (i work that out to explain why eclipse not giving you a messages). You see, a configuration that could not be read is not a error. This means your application works great (be proud of your first try), but the configuration is wrong! To solve the configuration drop that doctype and ns.
Triangle triangle = (Triangle)factory.getBean("Triangle.class"); will not find a definition. Use Triangle triangle = factory.getBean(Triangle.class); instead because you have not to cast.
So the main should be like this:
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(new FileSystemResource("spring.xml"));
Triangle triangle = factory.getBean(Triangle.class);
triangle.draw();
I'm migrating an application based on Alfresco 3.2r13 from linux/IntelliJ/Ant toward Windows/Eclipse.
Later the aimed will be to add Maven to the Eclipse project, but for now, I just want it to work.
Currently I'm facing the following issue:
I add the contentTypesModel.xml to the project, here are the first lines:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Optional meta-data about the model -->
<description>Example custom Model</description>
<author></author>
<version>1.0</version>
<!-- Imports are required to allow references to definitions in other models -->
<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0"
prefix="d"/>
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
<import uri="http://www.alfresco.org/grimoire/model/ma0189cstr/1.0" prefix="ma0189cstr"/>
<import uri="http://www.alfresco.org/grimoire/model/ma43110cstr/1.0" prefix="ma43110cstr" />
<import uri="http://www.alfresco.org/grimoire/model/baremesSys/1.0"
prefix="baremesSys"/>
<import uri="http://www.alfresco.org/grimoire/model/baremes/1.0"
prefix="baremes"/>
<import
uri="http://www.alfresco.org/grimoire/model/workflow/baremes/perimetres/1.0"
prefix="perimetres"/>
</imports>
<!-- Introduction of new namespaces defined by this model -->
<!-- NOTE: The following namespace my.new.model should be changed to reflect
your own namespace -->
<namespaces>
<namespace uri="http://www.alfresco.org/grimoire/model/contenttypes/1.0"
prefix="GPCT"/>
</namespaces>
When trying to Run the Tomcat Server, I got the following error trace:
> 23 déc. 2015 16:28:44,047 ERROR [web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'extension.dictionaryBootstrap' defined in file [D:\TomcatGrimoire\webapps\GrimoireMk0\WEB-INF\classes\alfresco\extension\gp-models-context.xml]: Invocation of init method failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: 11230001 Could not import bootstrap model alfresco/extension/contentTypesModel.xml
Caused by: org.alfresco.service.cmr.dictionary.DictionaryException: 11230001 Could not import bootstrap model alfresco/extension/contentTypesModel.xml
at org.alfresco.repo.dictionary.DictionaryBootstrap.onDictionaryInit(DictionaryBootstrap.java:150)
at org.alfresco.repo.dictionary.DictionaryBootstrap.bootstrap(DictionaryBootstrap.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1242)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1208)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:69)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.alfresco.service.cmr.dictionary.DictionaryException: 11230000 Failed to compile model GPCT:gpcontenttypeswfmodel
at org.alfresco.repo.dictionary.CompiledModel.<init>(CompiledModel.java:112)
at org.alfresco.repo.dictionary.M2Model.compile(M2Model.java:134)
at org.alfresco.repo.dictionary.DictionaryDAOImpl.putModel(DictionaryDAOImpl.java:273)
at org.alfresco.repo.dictionary.DictionaryBootstrap.onDictionaryInit(DictionaryBootstrap.java:146)
... 34 more
Caused by: org.alfresco.service.namespace.NamespaceException: URI http://www.alfresco.org/grimoire/model/ma0189cstr/1.0 cannot be imported as it is not defined (with prefix ma0189cstr
at org.alfresco.repo.dictionary.CompiledModel.createLocalPrefixResolver(CompiledModel.java:209)
at org.alfresco.repo.dictionary.CompiledModel.constructDefinitions(CompiledModel.java:134)
at org.alfresco.repo.dictionary.CompiledModel.<init>(CompiledModel.java:94)
... 37 more
The file wfMA0189Constraints.xml contains the following definition:
<!-- Optional meta-data about the model -->
<description>MA0189 Constraints Workflow Model</description>
<author>FSE</author>
<version>1.0</version>
<!-- Imports are required to allow references to definitions in other models -->
<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
</imports>
<!-- Introduction of new namespaces defined by this model -->
<namespaces>
<namespace uri="http://www.alfresco.org/grimoire/model/ma0189cstr/1.0" prefix="ma0189cstr"/>
</namespaces>
As far as I understand the error, the content of the file is not acknowledged by the tomcat server. The thing is that after a check the tomcat build does contain the file.
So I'm stuck on this error. Any hlep will be welcome.
Thanks in advance and happy holidays.
There should be a spring context file deployed probably in the extension path.
The name of the file usually ends with "-context.xml".
Look for a context file that contains the name of the content model file: you should see the definition of a bean with parent="dictionaryModelBootstrap".
If you cannot find this context file, try to find it in your source code and see how it was packaged by intellij/ant
Please find more details at:
http://docs.alfresco.com/5.1/tasks/dev-extensions-content-models-tutorials-deploy-model.html
The issue might be caused by the order in which the content models are loaded. This might explain the difference between IntelliJ and Eclipse.
If you want to be sure about the order you can use depends-on as an attribute in the bean initialization.
If the models are in different modules you can also use module dependencies.
See example: http://docs.alfresco.com/4.2/concepts/dev-extensions-modules-module-properties.html
It seems like you are missing entry of "wfMA0189Constraints.xml" model file in your context file. That is the reason Alfresco is not able to pickup that model and hence it shows prefix as unidentified prefix.
Based on your logs I see you are using "gp-models-context.xml" as your context file. Are you able to see entry of this model file (wfMA0189Constraints.xml) there?
If you are sure that no context files are loading the model, it is possible that the model is manually uploaded in "Data Dictionary/model". This folder can be used to add new content models dynamically on a running instance of Alfresco.
Is it possible that someone wanted to make these constraints modifiable by end users?
Do you have an instance where the deployment worked? If yes, could you check if the model is deployed in that folder?
I use Windows10 Pro 32bit ENG, EclipseEE Mars, Java 8_66. If I want create a easy bean project with Spring and run it it show me a error in Windows dialog. When I enter this dialog it generated exception.
Java Virtual Machine Launcher - Error :
A JNI error has occurred, please check your installation and try it again.
I have in CLASSPATH : Apache *.jars
•commons-logging-1.2.jar
•commons-logging-1.2-javadoc.jar
Spring *.jars
•spring-aop-4.1.5.RELEASE.jar
•spring-beans-4.1.5.RELEASE.jar
•spring-context-4.1.5.RELEASE.jar
•spring-aspects-4.1.5.RELEASE.jar
•spring-context-support-4.1.5.RELEASE.jar
•spring-core-4.1.5.RELEASE.jar
•spring-web-4.1.5.RELEASE.jar
•spring-webmvc-4.1.5.RELEASE.jar
•spring-expression-4.1.5.RELEASE.jar
I have the tested Java 8_60 vs Spring 4.1.5, Java 8_66 vs Spring 4.1.5 or 4.2.2.
KlientMetaTest.java
package klient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import server.ServerVypis;
public class KlientMetaTest {
public static void main(String[] args) {
#SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/Beans.xml");
ServerVypis obj = (ServerVypis) context.getBean("mujSpring"); // id beanu
obj.getMessage();
}
}
ServerVypis.java
package server;
public class ServerVypis {
private String message;
public void setMessage(String message){
this.message = message; }
public void getMessage(){
System.out.println("Zde je tvuj Spring vypis : " + message); }
}
beans.xml which is in /META-INF/ folder
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="mujSpring" class="server.ServerVypis">
<property name="message" value="Vypis z \META-INF\Bean.xml"/>
</bean>
</beans>
Exception which was showing in console :
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
I have faced the same problem.
I made some changes in my pom.xml. Ff you are using the dependency of javax mail as well aws sdk then make sure that javax mail should be declare before the aws sdk's.
If you change the sequence then it will show the above error as it's loading jars in wrong sequence.As this worked in mine case, Hope this will work for you!
Problem solved. After I install Windows10, it broke my access to folders when I have save the external jars of frameworks.
I'm a newbie for Spring and I was referring to this tutorial for my first Spring project. After follow all the instruction, I try to run the program but I'm having this error.
May 26, 2015 11:42:45 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#31221be2: startup date [Tue May 26 11:42:45 CST 2015]; root of context hierarchy
May 26, 2015 11:42:45 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/expression/ParserContext
at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:553)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.tutorialspoint.MainApp.main(MainApp.java:9)
Caused by: java.lang.ClassNotFoundException: org.springframework.expression.ParserContext
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more
Any idea where I did the wrong. As I know I was following the tutorial correctly.
CODE
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
Beans.XML
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
<property name="message" value="Hello World!"/>
</bean>
</beans>
Check if you have added all the required jars in your classpath.
The class org.springframework.expression.ParserContext lies inside spring-expresssion-YOUR_SPRING_VERSION.jar Check if you have this jar added on classpath.
I was having the same issue. But I found my mistake.
My mistake was, I created "Beans.xml" inside com.tutorialspont package.
The solution for me was "Beans.xml" has to be created directly under src folder.
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/expression/PropertyAccessor
at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:553)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.javahonk.client.TestWebService.main(TestWebService.java:19)
Caused by: java.lang.ClassNotFoundException: org.springframework.expression.PropertyAccessor
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
Solution to the above problem:This happens if spring-expression-xxx.Release.jar in not available in your class path. Please add spring-expression-3.2.3.RELEASE or latest version jar in your class path to fix this issue.
I'm trying to get CXF to work with spring, maven on weblogic.the project compile/build fine, but when I try to deploy it I got this error:
<User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ibanInfos': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/ws/EndpointReference.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ibanInfos': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/ws/EndpointReference
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
Truncated. see log file for complete stacktrace
java.lang.NoClassDefFoundError: javax/xml/ws/EndpointReference
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
at java.lang.Class.getDeclaredMethods(Class.java:1763)
at java.beans.Introspector$1.run(Introspector.java:1265)
at java.security.AccessController.doPrivileged(Native Method)
Any idea how to solve this?
In fact, I'm using the java first strategy to generate WSDL.
Here is my spring file :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:service-definition-beans.xml"/>
<jaxws:endpoint id="ibanInfos" implementor="#ibanInfosService" address="http://localhost:7001/IbanInfos" />
</beans>
Make sure you have jaxws-api-2.3.1.jar in your classpath.
It can be download via the above link or from maven.
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
I finally found the problem : im actually using weblogic under 10.0 version which provide Jaxws2.0 that doest contain EndPointInterface.
A workaroud is to add the jar into setDomainEnv.sh and it will work perfectly. Thanks alot for your answers.
EndpointReference was introduced in JAX-WS 2.1, and JAX-WS 2.1 is included into JRE since Java 1.6.0_04.
So, if EndpointReference is unavailable in your environment you need to upgrade your JRE/JDK, or include a recent version JAX-WS API as a separate dependency.
Seems like this class is not in your classpath. You should add the relevant item to your POM.
From searching the web, this class is present in many libraries. Here is an excerpt for including such aritfact:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.3</version>
</dependency>
Looks like you are using higher version of java, for an application which is not compatible to it yet.
If you are building the app in Intellij, try changing the jdk setup to java11 or java8, this would fix the issue.