Spring,SpringMVC整合

一、(web.xml)配置spring/amq监听

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
二、(web.xml)springDispatcher配置
<servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
</servlet>

三、(web.xml)配置spring-mapping

<servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
</servlet-mapping>

四、创建spring-servlet.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans     
           http://www.springframework.org/schema/beans/spring-beans-4.2.xsd     
           http://www.springframework.org/schema/context     
           http://www.springframework.org/schema/context/spring-context-4.2.xsd    
           http://www.springframework.org/schema/mvc     
           http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">

	<mvc:annotation-driven>
		<mvc:message-converters register-defaults="false">
			<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
			<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
			<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
			<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
			<bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
				<property name="supportedMediaTypes">
					<list>
						<value>text/jsp;charset=UTF-8</value>
						<value>application/json;charset=UTF-8</value>
					</list>
				</property>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>

	 <!--静态资源 -->
	<mvc:default-servlet-handler />

	<!-- 组件扫描 "controller" 是你的控制层的代码的包名 -->
	<context:component-scan base-package="controller" />


	<!-- 视图解析 "/"是你的视图路径,也就是网页文件的路径 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/"/>
		<property name="suffix" value=".jsp"/>
	</bean>

</beans>

五、创建applicationContext.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans     
           http://www.springframework.org/schema/beans/spring-beans-4.2.xsd     
           http://www.springframework.org/schema/context     
           http://www.springframework.org/schema/context/spring-context-4.2.xsd    
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

	<!-- 组件扫描 根据你的包名而定-->
	<context:component-scan base-package="util" />
	<context:component-scan base-package="dao" />
	<context:component-scan base-package="serve" />
	<context:component-scan base-package="entity" />

	<!-- 数据源 连接数据库 -->
	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/crm" />
		<property name="username" value="wjl" />
		<property name="password" value="123" />
	</bean>

	<!-- 数据库操作对象 -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<constructor-arg name="dataSource" index="0" ref="dataSource"></constructor-arg>
	</bean>

	<!-- sessionFactory配置 如果需要  可以使用-->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mapperLocations" value="classpath*:dao/*Mapper.xml" />

		<!-- 配置mybatis分页插件PageHelper -->
		<property name="plugins">
			<array>
				<bean class="com.github.pagehelper.PageInterceptor">
					<property name="properties">
						<!-- 什么都不配,使用默认的配置 -->
						<value></value>
					</property>
				</bean>
			</array>
		</property>
	</bean>

	<!-- mapperScanner配置 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="dao" />
	</bean>

</beans>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值