小编jpa*_*ack的帖子

为什么我的Spring Controller的请求映射在模拟WebApplicationContext中不起作用?

我在这里从Spring文档工作。我的目标是使用“ webAppContextSetup”选项与控制器一起测试我的弹簧配置,但是我很难将控制器的方法映射到TestDispatcherServlet内。到目前为止,我具有以下设置:

资料配置

<?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:context="http://www.springframework.org/schema/context"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <jpa:repositories base-package="com.example.test"/>

    <bean id="contractManagementDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="contractManagementDataSource"/>
        <!-- no need for the load time weaving from the spring documentation since we're using hibernate as our JPA provider -->
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"/>

    <context:property-placeholder location="classpath:config.properties"/>

</beans>
Run Code Online (Sandbox Code Playgroud)

MVC配置

<?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:mvc="http://www.springframework.org/schema/mvc" …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-test spring-test-mvc

3
推荐指数
1
解决办法
2179
查看次数

标签 统计

java ×1

spring ×1

spring-mvc ×1

spring-test ×1

spring-test-mvc ×1