0

我想我的设置崩溃了,因为我的映射不再工作而且我不知道为什么。这是我的 web.xml、applicationContext.xml payment-servlet.xml 和 payment.beans.xml。

**web.xml**

     <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <!-- Add Support for Spring -->
    <!-- Default applicationContext location: /WEB-INF/applicationContext.xml -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- exposes the request to the current thread -->
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

     <!-- springapp payment servlet -->
            <servlet>
                <servlet-name>payment</servlet-name>
                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                    <init-param>
                        <param-name>contextConfigLocation</param-name>
                        <!--  <param-value>classpath:/spring/servlet/payment-servlet.xml</param-value> -->
                        <param-value>file:**/webapp/META-INF/spring/servlet/payment-servlet.xml</param-value>
                    </init-param>
                <load-on-startup>1</load-on-startup>
            </servlet>
            <servlet-mapping>
                 <servlet-name>payment</servlet-name>
                  <url-pattern>/payment/*</url-pattern> 
                  <url-pattern>/paymentExternalData</url-pattern>
                  <url-pattern>/paymentInternalData</url-pattern> 
            </servlet-mapping>

            <!-- Welcome files -->
            <welcome-file-list>
                 <welcome-file>payment.jsp</welcome-file>
                 <welcome-file>payment.html</welcome-file>
            </welcome-file-list>
        </web-app>

**applicationContext.xml**

    <context:annotation-config />

         <!--  payment servlet 
        <import resource="classpath:/spring/payment.beans.xml"/> -->
        <import resource="file:**/webapp/META-INF/spring/payment.beans.xml"/>

        <!-- Auto scan the components -->
        <context:component-scan 
            base-package="com.app.payment.model.PaymentUser" />

**payment-servlet**

    <!-- Auto scan the components -->
    <context:component-scan base-package="at.dt_i.primesign.payment" />

    <!-- Payment controller --> 
    <bean class="at.dt_i.primesign.payment.controller.PaymentController">
    </bean> 

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- PropertyPlaceholderConfigurer 
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" depends-on="configuration">
        <property name="properties" ref="configuration" />
    </bean> -->
    <bean 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>/WEB-INF/configuration.properties</value>
        </property>
    </bean>

**payment.beans.xml**

    <context:annotation-config />
    <tx:annotation-driven /> 

    <bean id="paymentDao" class="com.app.payment.model.PaymentDAOImpl" />
    <bean id="paymentService" class="com.app.payment.PaymentServiceImpl" />

    <bean id="dataSource" 
             class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${database.driverClassName}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.username}" />
        <property name="password" value="${database.password}" />
    </bean>


    <bean id="paymentTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="paymentEntityManagerFactory" />
    </bean>

    <!-- -->
    <bean id="paymentJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="true" />
        <property name="generateDdl" value="${paymentJpaVendorAdapter.generateDdl}" />
        <property name="databasePlatform" value="${paymentJpaVendorAdapter.databasePlatform}" />
    </bean> 

    <bean id="paymentEntityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="profileDataSource" />
        <property name="jpaVendorAdapter" ref="paymentJpaVendorAdapter" />
        <property name="persistenceUnitName" value="payment" />
    </bean>

我的第一个问题:我的结构正确还是有更好的解决方案。主要目标是使用控制器方法 /paymentInternalData 和 /paymentExternalData 进行操作。但我认为 dispatchServlet 加载了一些不同的东西,因为映射不起作用,它只显示欢迎页面。但不是 2 个子页面。

我知道这主要是代码,但我不确定要发布什么,所以我发布了所有内容。希望任何人都可以提供帮助。

4

1 回答 1

1

我认为您的 servlet 网址模式是正确的:

             <servlet-mapping>
             <servlet-name>payment</servlet-name>
              <url-pattern>/payment/*</url-pattern> 
              <url-pattern>/paymentExternalData</url-pattern>
              <url-pattern>/paymentInternalData</url-pattern> 
            </servlet-mapping>

但是

文件:**/webapp/META-INF/spring/servlet/payment-servlet.xml

无法加载 payment-servlet.xml 文件。如果您的 META-INF 在 webapp 目录下,那么您可以这样做:

                <init-param>
                    <param-name>contextConfigLocation</param-name>
                    <!--  <param-value>classpath:/spring/servlet/payment-servlet.xml</param-value> -->
                    <param-value>/META-INF/spring/servlet/payment-servlet.xml</param-value>
                </init-param>

或删除 init-param 块并将 payment-servlet.xml 移动到 web.xml 所在的 webapp/WEB-INF/ 目录下。

于 2013-08-21T12:45:49.970 回答