I'm trying to set up a Java Web Application to run on my local Tomcat server. I've made progress, but my current issue is that when I try to deploy to the server, I get the following error.
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/SiteAdmin-servlet.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getResourceLoader()Lorg/springframework/core/io/ResourceLoader;
After some time with Google, I came to understand that this a dependency issue of some sort. Here are the Spring dependencies I'm currently using
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-js</artifactId>
<version>2.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.3.RELEASE</version>
<!--<version>4.3.2.RELEASE</version>-->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>2.5.5</version>
<!--<version>4.3.2.RELEASE</version>-->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springmodules</groupId>
<artifactId>spring-modules-validation</artifactId>
<version>0.8a</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>2.5.5</version>
</dependency>
As can be seen above, I tried updating the spring-core and the spring-beans dependencies to later versions, but the error persists. I want to avoid changing the dependencies too much, since when I tried updating all of them it caused errors elsewhere in my code. Any help in how to approach this issue would be appreciated.
If it helps, I'm using Netbeans and Java 6. I want to avoid changing that Java version if I can.
Fixed the problem guys. There was an old spring-core dependency jar in the classpath. I didn't notice it at first because it was only called spring.jar. Got rid of it, error's gone.
Related
I just upgraded Tapestry 5.3.8 to 5.4.0, and then I found the #Secured annotation has an issue. If I go to page which has this #Secured, the exception org/apache/tapestry5/services/TransformMethodSignature and could not initialize class nu.localhost.tapestry5.springsecurity.services.internal.TransformConstants2 will thrown (with no detail). Is it no longer supported in 5.4.0? Or do I need to upgrade something in my pom.xml?
pom.xml
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-core</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-hibernate</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-upload</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-spring</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-kaptcha</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.got5</groupId>
<artifactId>tapestry5-jquery</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>com.github.lltyk</groupId>
<artifactId>tapestry-spring-security</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.0.RELEASE</version>
<scope>test</scope>
</dependency>
Well, after struggling for days, I'm finally figured out that this library:
<dependency>
<groupId>com.github.lltyk</groupId>
<artifactId>tapestry-spring-security</artifactId>
<version>3.0.3</version>
</dependency>
Can not keep up with Tapesty 5.4, because it has a class: nu.localhost.tapestry5.springsecurity.services.internal.TransformConstants2 that refers to org.apache.tapestry5.services.TransformMethodSignature which is not available any longer in Tapestry 5.4.
I've tried to upgrade tapestry-spring-security to highest version: 3.0.5, but still can't keep up with Tapestry 5.4, so the only way to solve it, is to remove it. And to replace all the functionalities which was provided by tapestry-spring-security, I need to add 4 new libs to pom (in your case you might need to add more or less than 4): spring-security-core: 4.0.0.M1, spring-security-web: 4.2.3.RELEASE, spring-dao: 2.0.8, servlet-api: 2.5
In my case, I need to copy the code from the original source for these classes: LogoutService (interface), LogoutServiceImpl, IfRole and IfLoggedIn. Create the files and paste the code.
I am trying to upgrade to Spring - 4.3.4.RELEASE,
Spring-security 4.2.3
Here is what I have in my pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.9.RELEASE</version>
When I start my server, I am getting an error of NoSuchMethodError,
Caused by: java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableListableBeanFactory.resolveNamedBean(Ljava/lang/Class;)Lorg/springframework/beans/factory/config/NamedBeanHolder;
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:579)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:546)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:707)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:680)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:354)
which is for the Spring Beans library missing this resolveNamedBeanmethod. I have found that this method was introduced since spring 4.3.3. But my dilemma is that I do not have an older version of spring-bean anywhere in my pom or in my local repository.
Where do I start looking for the older version of the bean library? Could someone please point me in the right direction as I am just stuck.
I would appreciate any suggestion.
Thanks
screenshot of what my local repository has for spring bean
Screenshot of what JARS in my Maven dependencies folder in my project
Check what version of spring-orm you have in directory with compiled classes. Seems like your project is not fully recompiled. Try to recompile everything in order to be sure that in runtime you have appropriate version of spring-beans. Now it looks like new up-to-date version of spring-orm tries to utilize old version of spring-beans.
I have a spring-webmvc based web application. It used the org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer which is not supported by the spring version used in my project.
My project's spring dependency look like this:
I want to upgrade all spring dependency from 3.1.1 to 4.1.2. How to do that?
You should move from a hardcoded version of a spring version inside a pom.xml to a property, e.g.
inside your properties
<springframework.version>4.0.2.RELEASE</springframework.version>
inside your dependencies
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<!-- spring security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${springframework.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${springframework.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${springframework.security.version}</version>
</dependency>
with this setup its easy to migrate the versions, the listed deps are just copy/paste, don't take it for granted, use what you need
you can update dependency like this globally :
<properties>
<spring.version>4.1.2.RELEASE</spring.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
using this global dependency version management, you can avoid some version compatibility exception.
Since you are using Maven, your pom-dependencies will probably look like
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
...
You could replace "3.1.1.RELEASE" with ${spring-version}, and add the following to your pom-file
<properties>
<spring-version>4.1.2</spring-version>
</properties>
It will make it easier to change version for all your spring dependencies
If you using maven build tool,so it's very simple to upgrade spring 3 to spring 4 you just open pom.xml file in the properties xml tag just change the version 3.x.x to 4 something. e.g:
<org.springframework-version>3.0.2.RELEASE</org.springframework-version>
to
<org.springframework-version>4.0.2.RELEASE</org.springframework-version>
In my log4j.properties I have the following line:
log4j.appender.queue=org.springframework.amqp.log4j.AmqpAppender
In my pom.xml I have the following spring related inclusions:
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>
When I startup the application, I see the following exception:
log4j:ERROR Could not instantiate class [org.springframework.amqp.log4j.AmqpAppender].
java.lang.ClassNotFoundException: org.springframework.amqp.log4j.AmqpAppender
...
What dependency do I require to make use of org.springframework.amqp.log4j.AmqpAppender ?
You have correct dependency, but class is different a bit:
org.springframework.amqp.rabbit.log4j.AmqpAppender
Pay attention to the package, please.
Not sure I think the appender you found is a different one. There is one appender in:
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>1.3.6.RELEASE</version>
</dependency>
from spring-ampq.
The spring version maybe different too.
I want objects of my Tomcat web application to be controlled by Maven's pom and Spring's IoC, including session scoped beans. My application consists of several objects which are accessed from jsp files.
What is the best way to design such an application with suit tools? Should I use Spring MVC Project template though I don't want to implement MVC tiers? Or there is another template somewhere on the Net?
The way I do using STS is like this. Go to
File --> New --> Project --> Maven Project--> Create a simple project (skip archtype) --> Enter the Artifact details.
For Example: Group Id: com.examples
Artifact Id: MyProject
Click on Finish.
Now Right Click the project in Project Explorer and the Select Spring Tools--> Add Spring Project Nature.
I usually use simple project because I like using the same pom.xml across projects and add/remove dependencies when needed.
Sample pom.xml to get going with Spring
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.1.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.1.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.0.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>