Spring framework bean error [closed] - java

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();

Related

Spring Dependency Injection by Constructor - Error creating bean, caused by: java.lang.IncompatibleClassChangeError

I just started to learn Spring framework. I was learning about Spring Dependency Injection by Constructor and came across this error when I tried to run the code. Please help me resolve this error and explain what makes this error occure. Thank you.
Here is my code:
ActiveMQMessage.java
package com.infotech;
public class ActiveMQMessage {
public void sendMessage() {
System.out.println("Send message via ActiveMQMessage..");
}
}
Communication.java
package com.infotech;
public class Communication {
private ActiveMQMessage activeMQMessage;
public Communication(ActiveMQMessage activeMQMessage) {
super();
this.activeMQMessage = activeMQMessage;
}
public void communicate() {
activeMQMessage.sendMessage();
}
}
applicationContext.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="communication" class="com.infotech.Communication">
<constructor-arg name="activeMQMessage" ref="activeMQMessage"></constructor-arg>
</bean>
<bean id="activeMQMessage" class="com.infotech.ActiveMQMessage"></bean>
</beans>
Main.java
package com.infotech;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Communication communication = context.getBean("communication", Communication.class);
communication.communicate();
context.close();
}
}
This is the error:
Mei 30, 2018 9:13:55 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#3830f1c0: startup date [Wed May 30 09:13:55 ICT 2018]; root of context hierarchy
Mei 30, 2018 9:13:55 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Mei 30, 2018 9:13:55 AM org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'communication' defined in class path resource [applicationContext.xml]: Unexpected exception during bean creation; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.LocalVariableTableParameterNameDiscoverer$ParameterNameDiscoveringVisitor has interface org.springframework.asm.ClassVisitor as super class
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'communication' defined in class path resource [applicationContext.xml]: Unexpected exception during bean creation; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.LocalVariableTableParameterNameDiscoverer$ParameterNameDiscoveringVisitor has interface org.springframework.asm.ClassVisitor as super class
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at com.infotech.Main.main(Main.java:10)
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.core.LocalVariableTableParameterNameDiscoverer$ParameterNameDiscoveringVisitor has interface org.springframework.asm.ClassVisitor as super class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass(LocalVariableTableParameterNameDiscoverer.java:116)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:89)
at org.springframework.core.PrioritizedParameterNameDiscoverer.getParameterNames(PrioritizedParameterNameDiscoverer.java:67)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
... 10 more
I'd at least try removing the name= attribute from the <constructor-arg>. This is not strictly necessary if there is only one constructor that could possibly match, and while what you have seems like it should work, the error message does seem to indicate something related to name resolution.
com.spring.core and com.spring.asm jar files must be different versions in your project.
asm jar hasnt been updated in a long time thats why you need to downgrade your core jar file.

Java Virtual Machine Launcher : A JNI Error with Spring

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.

Spring - Loading XML bean definitions from class path resource [Beans.xml]- NoClassDefFoundError

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.

Exception Due to referring struts.dtd file from internet/local

From morning facing Exception while running struts2 apps....application was working yesterday
There's a problem in loading some struts2-jquery jar even though they exist in WEB-INF/lib
After browsing I got some solution to make change in struts.xml <!DOCTYPE ....>
like changing
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
to
<!DOCTYPE struts SYSTEM "../dtds/struts-2.0.dtd">
or
<!DOCTYPE struts SYSTEM "struts-2.0.dtd">
For local referencing struts.dtd but none of these working..
Exception on console :
Unable to load configuration. - action - file:/D:/.........plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/XXXXXXXX/WEB-INF/classes/struts.xml:25:88
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:48)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4584)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5262)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5257)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: Error building results for action getGroups in namespace - action - file:/D:/T....plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/XXXXXXX/WEB-INF/classes/struts.xml:25:88
This has been resolved and was due to a change in Apache project publishing mechanisms.
For details :
https://issues.apache.org/jira/browse/WW-3979

Spring can't find configuration in path

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

Categories