RAS
RAS

Reputation: 197

I can not run the Spring and MyBatis application

When you try to run the falls with the error:

org.springframework.beans.factory.BeanCreationException: Error creating bean  with name 'sqlSessionFactory' defined in class path resource [application- context.xml]: Error setting property values; nested exception is  org.springframework.beans.PropertyBatchUpdateException; nested  PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy

application-context.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.xsd">

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:db.properties</value>
        </list>
    </property>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${db.driver}"/>
    <property name="url" value="${db.url}"/>
    <property name="username" value="${db.user}"/>
    <property name="password" value="${db.password}"/>
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="typeAliasesPackage" value="com.rest.service.entity" />
</bean>

<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
    <property name="mapperInterface" value="com.rest.service.mapping.UserMapper" />
    <property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

I do not understand what is wrong, do these instructions: http://www.mybatis.org/spring/getting-started.html

The context is initialized: public class ApplicationInitializer implements WebApplicationInitializer {

private static final String DISPATCHER = "dispatcher";


public void onStartup(ServletContext servletContext) throws ServletException {
    XmlWebApplicationContext appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:application-context.xml");
    ServletRegistration.Dynamic dispatcher =
            servletContext.addServlet(DISPATCHER, new DispatcherServlet(appContext));
    dispatcher.addMapping("/");
    dispatcher.setLoadOnStartup(1);
   }
}

With what may be related problem?

Upvotes: 1

Views: 1305

Answers (1)

RAS
RAS

Reputation: 197

I just added it in my pom.xml and it is work:

   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</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-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>

Upvotes: 1

Related Questions