0

I think I crashed my setup because my mapping isn't working any more and I don't know why. Here are my web.xml, applicationContext.xml payment-servlet.xml and 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>

My first question: Is my structure right or is there a better solution. the main goal is to operate with to controller methods /paymentInternalData and /paymentExternalData. But I think the dispatchServlet loads something different because the mapping is not working it only shows the welcome page. but not the 2 sub pages.

I know this is mainly code but I'm not sure what to post, so I posted everything. hopefully anybody can help.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
vicR
  • 789
  • 4
  • 23
  • 52

1 Answers1

1

I think your Url-pattern for servlet is correct :

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

But the

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

is not able to load the payment-servlet.xml file. If your META-INF is under webapp directory then you can do this :

                <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>

or Remove the init-param block and move payment-servlet.xml under webapp/WEB-INF/ directory where web.xml present.

Ankush T
  • 114
  • 1
  • 10