This question has already been answered:

I used an example for my application. Idea does not issue any warnings, but at startup I get errors like:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [data.xml]

Offending resource: ServletContext resource [/WEB-INF/root-context.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/data.xml]; nested exception is java.lang.NoClassDefFoundError: org / springframework / context / event / EventListenerFactory

Apparently problems with data.xml, but I just can not find them.

<?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" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.connection.charSet">UTF-8</prop> </props> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseUrl}" p:username="${jdbc.username}" p:password="${jdbc.password}"/> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.properties"/> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="messages"/> <property name="defaultEncoding" value="UTF-8"/> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> </beans> 

root.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" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" 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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd" > <context:annotation-config/> <context:component-scan base-package="com"/> <import resource="data.xml"/> </beans> 

web.xml

 <?xml version="1.0" encoding="UTF-8" ?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/root-context.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- Encoder --> <filter> <filter-name>charsetFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>charsetFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> 

jdbc.properties

 jdbc.driverClassName= org.postgresql.Driver jdbc.dialect=org.hibernate.dialect.PostgreSQLDialect jdbc.databaseurl=jdbc:postgresql://localhost:5432/shopbase jdbc.username=user jdbc.password=1234 

hibernate.cfg.xml

 <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <mapping class="com.model.Product" /> </session-factory> </hibernate-configuration> 

And the model itself just in case:

package com.model;

 import javax.persistence.*; @Entity @Table(name = "product") public class Product { @Id @Column(name = "id") @GeneratedValue private int id; @Column(name = "name") private String name; @Column(name = "price") private float price; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } } 

pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>shopGroup</groupId> <artifactId>shopTest</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <url>http://maven.apache.org</url> <dependencies> <!--Spring--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>4.3.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.3.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!--Hibernate--> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0.2</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>3.2.0.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.6.9.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.6.9.Final</version> </dependency> </dependencies> </project> 

I can not understand what the problem is. Everything is done on manuals.

Reported as a duplicate by members enzo, user194374, zRrr , fori1ton , Grundy Jul 10 '16 at 18:58 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

1 answer 1

You have a "mess" in pom.xml . All Spring MVC dependencies must be the same version. See what you get in the classpath as a result.

 » mvn dependency:tree [INFO] shopGroup:shopTest:war:1.0-SNAPSHOT [INFO] +- org.springframework:spring-webmvc:jar:4.1.4.RELEASE:compile [INFO] | +- org.springframework:spring-core:jar:4.1.4.RELEASE:compile [INFO] | | \- commons-logging:commons-logging:jar:1.2:compile [INFO] | +- org.springframework:spring-expression:jar:4.1.4.RELEASE:compile [INFO] | \- org.springframework:spring-web:jar:4.1.4.RELEASE:compile [INFO] +- org.springframework:spring-context:jar:4.1.4.RELEASE:compile [INFO] | \- org.springframework:spring-aop:jar:4.1.4.RELEASE:compile [INFO] +- org.springframework:spring-beans:jar:4.1.4.RELEASE:compile [INFO] +- org.springframework:spring-jdbc:jar:3.0.6.RELEASE:compile [INFO] +- org.springframework:spring-orm:jar:4.3.0.RELEASE:compile [INFO] +- org.springframework:spring-tx:jar:4.3.0.RELEASE:compile [INFO] +- org.springframework.security:spring-security-web:jar:4.1.0.RELEASE:compile [INFO] | \- aopalliance:aopalliance:jar:1.0:compile [INFO] +- org.springframework.security:spring-security-config:jar:4.1.0.RELEASE:compile [INFO] +- org.springframework.security:spring-security-core:jar:4.1.0.RELEASE:compile [INFO] +- javax.servlet:jstl:jar:1.2:compile [INFO] +- javax.persistence:persistence-api:jar:1.0.2:compile [INFO] +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile [INFO] | \- org.slf4j:slf4j-api:jar:1.5.8:compile [INFO] +- org.hibernate:hibernate-core:jar:3.6.9.Final:compile [INFO] | +- antlr:antlr:jar:2.7.6:compile [INFO] | +- commons-collections:commons-collections:jar:3.1:compile [INFO] | +- dom4j:dom4j:jar:1.6.1:compile [INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile [INFO] | \- javax.transaction:jta:jar:1.1:compile [INFO] \- org.hibernate:hibernate-entitymanager:jar:3.6.9.Final:compile [INFO] +- cglib:cglib:jar:2.2:compile [INFO] | \- asm:asm:jar:3.1:compile [INFO] \- javassist:javassist:jar:3.12.0.GA:compile 

View the latest current dependency versions on Maven Central . It should turn out like this:

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>shopGroup</groupId> <artifactId>shopTest</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <properties> <spring.version>4.3.0.RELEASE</spring.version> <spring-security.version>4.1.0.RELEASE</spring-security.version> <servlet-api.version>3.1.0</servlet-api.version> <jstl.version>1.2</jstl.version> </properties> <dependencies> <!--Spring--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> <version>${spring-security.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>${spring-security.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>${spring-security.version}</version> </dependency> <!-- остальные зависимости --> </dependencies> </project> 

You can use the pom.xml example from the spring-showcase

There is also a simple way to specify Spring dependencies via BOM (Bill of Materials)

PS Current Hibernate 4.x or 5.x

  • Thank. Dependencies corrected, but the error did not disappear. In the Product.java model, the @Table names (name = "product") are underlined, in quotes. Also all @Column. - Alex_St 2:44 pm
  • @Alex_St Well, I didn’t add Hibernate dependencies to the example, because you had an error with Spring. Leave the ones that you had, just update the version (link in the post). - enzo
  • Could there be a problem with something else besides dependencies? Or do I need to deal with this longer? It seems to have done everything, as you said, but it does not help. The error is the same ( - Alex_St
  • I cannot see from here what is happening there :) Apparently you just need to start with more basic examples. First, sort out what dependencies you generally have in pom.xml and why, how the Spring application starts, how the JSP View Resolver connects, make sure that a simple JSP page is displayed. Then you will fasten Hibernate. And then Spring Security. - enzo
  • one
    Well, then you just did not choose the best example. Here, take something like that . There are two options: XML and Java config, full sources at the bottom of the page. You can also look in the direction of Spring Boot, for which you can generate a project template with all dependencies . In it, everything you need is configured in one file. - enzo