在调度程序servlet中配置多个控制器

时间:2011-07-15 00:09:54

标签: spring-mvc

我是spring-hibernate集成的新手。

我试图通过jsp表单将数据输入数据库,当对象试图持久化时,我得到一个空指针异常。

我检查了对象是否正在接收值,但确实如此。

我觉得是因为调度员服务器不允许我传递价值。

Bellow是我的调度员 - servlet。

如果有人能告诉我在调度程序servlet中配置多个控制器的方法,那就太棒了。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

        <!-- maps request URLs to Controller names -->
    <!-- <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> -->
    <!-- bean class="com.skopic.web.controller.UserController" /-->

  <bean name="/index/*.htm" class="com.skopic.web.controller.IndexController" >
        <!-- <property name="UserDAO" ref="myUserDAO" /> -->
    </bean>

    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
      <property name="prefix" value="/jsp/"/>
      <property name="suffix" value=".jsp"/>
    </bean>

    <bean id="propertyPlaceholderConfigurer"   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="locations">
         <list>
           <value>classpath:skopicportal.${SKAPP_ENV}.properties</value>
         </list>
       </property>
    </bean>
        <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/testdb"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
    </bean>

    <!-- <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="myDataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.skopic.web.controller.Tenant</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>
    </bean>

    <bean id="myTenantDAO" class="com.skopic.web.controller.TenantDAOImpl">
        <property name="sessionFactory" ref="mySessionFactory"/>
    </bean> -->


    <!-- User bean -->
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="myDataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.skopic.web.controller.User</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>
    </bean>

    <bean id="myUserDAO" class="com.skopic.web.controller.UserDAOImpl">
        <property name="sessionFactory" ref="mySessionFactory"/>
    </bean>

    <bean name="/user/*.htm" class="com.skopic.web.controller.UserController" >
        <property name="UserDAO" ref="myUserDAO" />
    </bean>
   <!--  <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> -->

    <mvc:annotation-driven/>

    <context:component-scan base-package="com.skopic.service"/>
    <context:component-scan base-package="com.skopic.web.controller"/>
</beans>

0 个答案:

没有答案