使用註解,並去掉@Controller 註解 ,防止衝突web
<context:annotation-config />spring
<context:component-scan base-package="com.mvc.*">sql
<context:exclude-filtertype="annotation" expression="org.springframework.stereotype.Controller"/>數據庫
</context:component-scan>express
從jdbc.properties中讀取數據庫的鏈接信息apache
<context:property-placeholder location="classpath:jdbc.properties"/>session
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">mvc
<property name="driverClassName" value="${jdbc.driver}"/>app
<property name="url" value="${jdbc.url}"/>框架
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
配置sessionfactory
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
<property name="mappingLocations">
<array>
<value>classpath*:com/mvc/entity/**/*.hbm.xml</value>
</array>
</property>
</bean>
<!-- HibernateTempate -->
<bean class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 事務管理器 -->
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 配置:控制器(C), 處理器映射, 視圖解析等 -->
<context:component-scan base-package="com.mvc.web" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 集成Spring框架 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 集成Spring MVC框架 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 字符集過濾器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- OpenSessionInView過濾器 -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
使用Spring + Hibernate + SpringMVC實現用戶註冊和登錄功能