1. 程式人生 > >深入講解SpringMVC配置檔案

深入講解SpringMVC配置檔案

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

	<context:annotation-config />

	<context:component-scan base-package="cn.com"  />

	<tx:annotation-driven transaction-manager="transactionManager" />

	<mvc:annotation-driven />

	<aop:aspectj-autoproxy proxy-target-class="true" />

	<!-- annotation的方法對映介面卡 -->
	<bean id="handlerAdapter"
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
	<!-- annotation預設的方法對映介面卡 -->
<!-- 	<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> -->
<!-- 	<property name="order" value="1" /> -->
<!-- 	</bean> -->

	<!-- 靜態檔案 -->
	<mvc:resources location="/assets/" mapping="/assets/**"></mvc:resources>

	<!-- 跳轉檔案的前後綴 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/view/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>

	<!-- ================mvc ================= -->


	<!-- ==================spring context=============== -->
	<!-- 引入配置檔案 -->
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>WEB-INF/conf/jdbc.properties</value>
				<!-- <value>WEB-INF/conf/conf.properties</value> -->
			</list>
		</property>
	</bean>

	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${driver}" />
		<property name="url" value="${url}" />
		<property name="username" value="${username}" />
		<property name="password" value="${password}" />
		<!-- 初始化連線大小 -->
		<property name="initialSize" value="${initialSize}"></property>
		<!-- 連線池最大數量 -->
		<property name="maxActive" value="${maxActive}"></property>
		<!-- 連線池最大空閒 -->
		<property name="maxIdle" value="${maxIdle}"></property>
		<!-- 連線池最小空閒 -->
		<property name="minIdle" value="${minIdle}"></property>
		<!-- 獲取連線最大等待時間 -->
		<property name="maxWait" value="${maxWait}"></property>
	</bean>

	<!-- spring和MyBatis完美整合,不需要mybatis的配置對映檔案 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<!-- 自動掃描mapping.xml檔案 -->
		<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
	</bean>

	<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
		<property name="basePackage" value="cn.com.**.dao" />
		<property name="properties">
			<value>mappers=cn.com.common.ssm.engine.mapper.BaseDao</value>
		</property>
	</bean>


<!-- 	(事務管理)transaction manager, use JtaTransactionManager for global tx -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- shiro -->

	<bean id="myRealm" class="cn.com.security.shiro.CustomRealm" />

	<!-- 安全管理器 -->
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<property name="realm" ref="myRealm" />
	</bean>

	<!-- Shiro過濾器 -->
	<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
		<!-- Shiro的核心安全介面,這個屬性是必須的 -->
		<property name="securityManager" ref="securityManager" />
		<!-- 身份認證失敗,則跳轉到登入頁面的配置 -->
		<property name="loginUrl" value="login.do" />
		<!-- 許可權認證失敗,則跳轉到指定頁面 -->
		<property name="unauthorizedUrl" value="/unauthor.jsp" />
		<!-- Shiro連線約束配置,即過濾鏈的定義 -->
		<property name="filterChainDefinitions">
			<value>
				/login.do=anon
				/**/*.do=authc
			</value>
		</property>
	</bean>

	<!-- 保證實現了Shiro內部lifecycle函式的bean執行 -->
	<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />

	<!-- 開啟Shiro註解 -->
<!-- 	<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor" /> -->
<!-- 	<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> -->
<!-- 		<property name="securityManager" ref="securityManager" /> -->
<!-- 	</bean> -->

</beans>


相關推薦

深入講解SpringMVC配置檔案

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-in

SpringMVC配置檔案詳解

1.<context:annotation-config/> 它的作用是隱式的向Spring容器註冊 AutowiredAnnotationBeanPostProcessor, CommonAnnotationBeanPostProcessor, PersistenceAnnotationBea

springMvc配置檔案

web.xm <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java

SpringMVC配置檔案詳解:<context:annotation-config/>和<context:component-scan base-package=""/>和<mvc:annotation-driven /> Spring配置

原文地址:https://www.cnblogs.com/lcngu/p/5080702.html Spring配置檔案詳解:<context:annotation-config/>和<context:component-scan base-package=""/>和<mvc:

SpringMVC配置檔案 中 mvc:view-controller 標籤的使用

原文轉載自:https://www.cnblogs.com/caoyc/p/5637894.html <mvc:view-controller path=""/>標籤的作用       工程WEB-INF目錄下面的JSP頁面,我們知道是不能直接使用URL訪問到。需

SpringMVC配置檔案The prefix "mvc" for element "mvc:annotation-driven" is not bound 的解決方法

在xml的beans中新增  xmlns:mvc="http://www.springframework.org/schema/mvc"  xsi:schemaLocation="http://www.springframework.org/schema/mvc http:

springmvc配置檔案web.xml中/與/*的區別

<!-- 配置springmvc的 DispatcherServlet ctrl+alt+向上鍵 --><servlet><servlet-name>springDispatcherServlet</servlet-name>

SpringMVC配置檔案報錯

       在配置註解處理器對映器、處理器介面卡時,已引入   xmlns:mvc="http://www.springframework.org/schema/mvc"和http://www.springframework.org/schema/mvc    http:/

六、springMVC-mvc.xml 配置檔案片段講解 (未使用預設配置檔名)

Xml程式碼 <context:component-scan/> 掃描指定的包中的類上的註解,常用的註解有: @Controller 宣告Action元件 @Service    宣告Service元件    @Service("myMovieLister

Spring+SpringMVC+MyBatis深入學習及搭建(三)——MyBatis全域性配置檔案解析

MyBatis的全域性配置檔案SqlMapConfig.xml,配置內容和順序如下: properties(屬性) setting(全域性配置引數) typeAliases(類名別名) typeHandlers(類名處理器) objectFactory(物件工廠) plugins(外掛) environm

Nginx配置優化及深入講解,大家可以聽一下

inactive 建立連接 epo 快速 一個 sync 檢測 wait 新建 隨著訪問量的不斷增加,需要對Nginx和內核做相應的優化來滿足高並發用戶的訪問,那下面在單臺Nginx服務器來優化相關參數。 1) Nginx.conf配置優化: worker_pr

springMVC配置檔案 mvc:default-servlet-handler/ 的作用

【Spring框架】<mvc:default-servlet-handler/>的作用 優雅REST風格的資源URL不希望帶 .html 或 .do 等字尾.由於早期的Spring MVC不能很好地處理靜態資源,所以在web.xml中配置DispatcherServlet的請求對映,

SpringMVC配置部署xml檔案

                                  SpringMVC配置部署xml檔案 之前沒有用框架,初識

轉:ssm spring+springmvc+mybatis中的xml配置檔案詳解

這幾天一直在整合SSM框架,雖然網上有很多已經整合好的,但是對於裡面的配置檔案並沒有進行過多的說明,很多人知其然不知其所以然,經過幾天的搜尋和整理,今天總算對其中的XML配置檔案有了一定的瞭解,所以拿出來一起分享一下,希望有不足的地方大家批評指正~~~ 首先   這篇文章暫時只對框架中所要用到的配

SpringMVC 學習 九 SSM環境搭建 (二) Spring配置檔案的編寫

spring配置檔案中需要乾的事情 (一)開啟  Service與pojo包的註解掃描 注意:spring 掃描與表對應的實體類,以及service層的類,不能用來掃描Controller層的類,因為Controller層的類需要由SpringMVC容器來管理,如果採用了Spring容器管理,就

springMVC-spring-Hibernate 開發學生管理系統簡單案例-配置檔案說明(三)

三、配置檔案說明 原始檔:https://download.csdn.net/download/flyingshadower/10628472 (1)在pom.xml寫入需要的各類依賴,自動下載依賴包。 <?xml version="1.0" encoding="UTF-8"?&g

spring整合springmvc和mybatis中的基本配置檔案

1  父工程統一管理依賴的porm.xml檔案 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoca

asp.netcore 深入瞭解配置檔案載入過程

前言     配置檔案中程式執行中,擔當著不可或缺的角色;通常情況下,使用 visual studio 進行建立專案過程中,專案配置檔案會自動生成在專案根目錄下,如 appsettings.json,或者是被大家廣泛使用的 appsettings.{env.EnvironmentName}.json;配置檔

SpringMVC關於dubbo的配置檔案

公司的老專案改造,網上找的xml真的不知所云,留此筆記 dubbo-provider.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2

ELK6.0日誌從收集到處理完整版教程(三)配置檔案講解

FIlebeat 配置檔案內容詳解: vi filebeat.yml filebeat.prospectors: #日誌型別 - type: log enabled: True # 日誌路徑可以寫多個,支援萬用字元 paths: - /tmp/test.