日期:2014-05-16 浏览次数:20455 次
现在springMVC的整合吧
第一步:web.xml的配置
?
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>?
???? ?dwr的配置()
?<servlet> ? ?? <servlet-name>dwr-invoker</servlet-name> ?? <servlet-class> org.directwebremoting.spring.DwrSpringServlet?</servlet-class> </servlet> <servlet-mapping> ? <servlet-name>dwr-invoker</servlet-name> ? <url-pattern>/dwr/*</url-pattern> </servlet-mapping>
?
第二步:WEB-INF/spring-servlet.xml的配置
?
<?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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- 定义一个视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /> </beans>
?
第三步:applicationContext.xml的配置
?
<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr" xmlns:mvc="http://www.springframework.org/schema/mvc" 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.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 激活spring的注解. --> <context:annotation-config /> <!-- 扫描注解组件并且自动的注入spring beans中. 例如,他会扫描@Controller 和@Service下的文件.所以确保此base-package设置正确. --> <context:component-scan base-package="net.rytong" /> <!-- 配置注解驱动的Spring MVC Controller 的编程模型.注:次标签只在 Spring MVC工作! --> <mvc:annotation-driven /> <mvc:default-servlet-handler default-servlet-name="IndexServlet"/> <!-- ********************************************** --> <!-- dwr启用 annotation 配置模式 --> <dwr:configuration> <dwr:convert type="bean" class="net.rytong.entity.Person" /> </dwr:configuration> <!-- pring容器中检查拥有@RemoteProxy 和 @RemoteMethod注解的类 --> <dwr:annotation-config /> <!-- 开启debug --> <dwr:controller id="dwrController" debug="true" /> <!-- ********************************************** --> <!-- 导入jdbc的配置文件 --> <import resource="jdbc-context.xml" /> </beans>
?
第四步:数据源jdbc-context.xml的配置
?
<?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:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"