亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

配置文件 web.xml + applicationContext.xml + 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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	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/aop?http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/context?http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/mvc?http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">

	<!--?配置自動掃描的包?-->
	<context:component-scan?base-package="com.imooc">
		<context:include-filter?type="annotation"
			expression="org.springframework.stereotype.Controller"?/>
		<context:exclude-filter?type="annotation"
			expression="org.springframework.stereotype.Service"?/>
		<context:exclude-filter?type="annotation"
			expression="org.springframework.stereotype.Repository"?/>
	</context:component-scan>

	<mvc:resources?location="/images/"?mapping="/images/**"?/>
	<mvc:resources?location="/js/"?mapping="/js/**"?/>
	<mvc:resources?location="/style/"?mapping="/style/**"?/>
	<mvc:resources?location="/img/"?mapping="/img/**"?/>

	<bean
		class="org.springframework.web.servlet.mvc.methdo.annotation.RequestMappingHandlerMapping"></bean>

	<bean
		class="org.springframework.web.servlet.mvc.methdo.annotation.RequestMappingHandlerAdapter">
		<property?name="cacheSeconds"?value="0"?/>
		<property?name="messageConverters">
			<list>
				<ref?bean="mappingJacksonHttpMessageConverter"?/>
				<ref?bean="mappingStringHttpMessageConverter"?/>
			</list>
		</property>
		<property?name="webBindInitializer"?ref="webBindInitializer"></property>
	</bean>

	<bean?id="mappingStringHttpMessageConverter"
		class="org.springframework.http.converter.StringHttpMessageConverter">
		<property?name="supportedMediaTypes">
			<list>
				<value>text/plain;charset=UTF-8</value>
				<value>application/json;charset=UTF-8</value>
			</list>
		</property>
	</bean>


	<bean?id="mappingJacksonHttpMessageConverter"
		class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
		<property?name="supportedMediaTypes">
			<list>
				<bean?class="org.springframework.http.MediaType">
					<constructor-arg?index="0"?value="application"></constructor-arg>
					<constructor-arg?index="1"?value="json"></constructor-arg>
					<constructor-arg?index="2"?value="UTF-8"></constructor-arg>
				</bean>
			</list>
		</property>
	</bean>

	<bean?id=""?webBindInitializer?"
		class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
		<property?name="conversionService">
			<bean
				class="org.springframework.core.convert.support.DefaultConversionService?/>
		</property>
	</bean>

	<!--?配置視圖解析器?如何把?handler?方法返回值解析為實際的物理視圖?-->
	<bean??id="
				ViewResolver?"
				class="org.springframework.web.servlet.view.InternalResourceViewResolver?">
				<property?name="ignoreAcceptHeader"?value="true"></property>
				<property?name="mediaTypes">
					<map>
						<entry?key="json"?value="application/json"></entry>
						<entry?key="xml"?value="application/xml"></entry>
					</map>
				</property>
				<property?name="defaultContentType"?value="text/html"></property>
				<property?name="favorParameter"?value="false"></property>
				<property?name="ViewResolvers">
					<list>
						<bean
							class="org.springframework.web.servlet.view.InternalResourceViewResolver">
							<property?name="order"?value="2"?/>
							<property?name="prefix"?value="/WEB-INF/views/"?/>
							<property?name="suffix"?value=".jsp"?/>
						</bean>
					</list>
				</property>
			</bean>

</beans>

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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"?xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans?
	???http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop?
		http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/context
		?http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/tx?
		http://www.springframework.org/schema/tx/spring-tx-4.3.xsd?">

	<!--?引入外部的屬性文件?-->
	<context:property-placeholder?location="classpath:/jdbc.properties"?/>

	<aop:aspectj-autoproxy?/>

	<!--?baosaomiao?-->
	<context:component-scan?base-package="com">
		<context:exclude-filter?type="annotation"
			expression="org.springframework.stereotype.Controller"?/>
	</context:component-scan>


	<!--?配置c3p0?連接池?-->
	<bean?id="dataSource"?class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property?name="driverClass"?value="${jdbc.driverClass}"?/>
		<property?name="jdbcUrl"?value="${jdbc.url}"?/>
		<property?name="user"?value="${jdbc.username}"?/>
		<property?name="password"?value="${jdbc.password}"?/>
	</bean>


	<!--?配置hibernate?相關屬性?-->
	<bean?id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<!--?注入連接池?-->
		<property?name="dataSource"?ref="dataSource"></property>
		<!--?hibernate?的相關屬性?-->
		<property?name="hibernateProperties">
			<props>
				<prop?key="hibernate.show_sql">true</prop>
				<prop?key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				<prop?key="hibernate.format_sql">true?</prop>
				<prop?key="hibernate.cache_use_second_level_cache">false</prop>
				<prop?key="hibernate.cache_use_query_cache">false</prop>
				<prop?key="current_session_context_class">thread</prop>
				<prop?key="hibernate.current_session_class">org.springframework.orm.hibernate4.SpringSessionContext
				</prop>

				<!--?它包含4個屬性:?*?create?:?會根據你的model類來生成表,但是每次運行都會刪除上一次的表,重新生成表,哪怕2次沒有任何改變?
					*?create-drop?:?根據model類生成表,但是sessionFactory一關閉,表就自動刪除?*?update?:?最常用的屬性,也根據model類生成表,即使表結構改變了,表中的行仍然存在,不會刪除以前的行?
					*?validate?:?只會和數據庫中的表進行比較,不會創建新表,但是會插入新值?-->
				<prop?key="hibernate.hbm2ddl.auto">update</prop>
			</props>
		</property>
		<!--?hibernate?映射文件?-->
		<property?name="packagesToScan">
			<list>
				<value>com.imooc.ssh.entity</value>
			</list>
		</property>
	</bean>

	<!--?配置事務管理器?-->
	<bean?id="transactionManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property?name="sessionFactory"?ref="sessionFactory"></property>
	</bean>

	<!--?開啟事務注解?-->
	<!--?<tx:annotation-driven?transaction-manager="transactionManager"?/>?-->

	<!--?開啟事務注解?-->
	<tx:advice?id="txAdvice"?transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method?name="get*"?read-only="true"?propagation="REQUIRED"?/>
			<tx:method?name="list*"?read-only="true"?propagation="REQUIRED"?/>
			<tx:method?name="find*"?read-only="true"?propagation="REQUIRED"?/>
			<tx:method?name="*"?read-only="false"?propagation="REQUIRED"
				rollback-for="Exception"?/>
		</tx:attributes>
	</tx:advice>

	<aop:config?proxy-target-class="true">
		<aop:advisor?pointcut="execution(public?*?com.imooc.*.Service.*Service.*())"
			advice-ref="txAdvice"?/>
	</aop:config>
</beans>

applicationContext.xml

<?xml?version="1.0"?encoding="UTF-8"?>
<web-app?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee?http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	id="WebApp_ID"?version="3.0">
	<display-name>SpringMVC_Spring_Hibernate</display-name>


	<!--?防止中文參數亂碼?放在前面?-->
	<filter>
		<filter-name>SetCharacterEncoding</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>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
			<!--?強制進行轉碼?-->
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>SetCharacterEncoding</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!--?spring?配置Listener?-->

	<!--?needed?for?ContextLoaderListener?-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:/applicationContext.xml</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!--?springmvc配置dispatcherServlet?-->

	<!--?The?front?controller?of?this?Spring?Web?application,?responsible?for?
		handling?all?application?requests?-->
	<servlet>
		<servlet-name>springDispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:/resources/springmvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!--?Map?all?requests?to?the?DispatcherServlet?for?handling?-->
	<servlet-mapping>
		<servlet-name>springDispatcherServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

web.xml


基于慕課網小伙伴 ?@須木一瓜3791985 ? 站在巨人的肩膀上 ? 謝謝這位小伙伴 ?但是 ?這個我沒有測試過 ?但是應該基本不會錯 ? 祝大家成功 ?不要輕易放棄 ? 如果需要jar包的加我微信 ?allpper 發你

正在回答

舉報

0/150
提交
取消

配置文件 web.xml + applicationContext.xml + Spring-servlet.xml

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號