天天看點

java web架構基礎_javaweb開發基本架構說明

一,配置檔案加載順序

web.xml ---->root-context.xml(加載spring容器) ---->springmvc.xml(springmvc的前端控制器)

root-context.xml做了那些事

2.1加載**.properties

2.2 配置掃描包和注解

2.3 資料源配置

2.4 Interceptor.

2.5 緩存(加載ehcache-context.xml)

2.6 task任務掃描注解

2.7 JavaBean映射工具庫(dozer-bean-mappings.xml)

2.8 加載 jdbc-context.xml shiro-context.xml

2.9 定義aspectj

springmvc.xml做了那些事

3.1 配置資源映射

3.2 配置FreeMarker

web.xml做了那些事

4.1 加載spring容器

4.2 加載springmvc的前端控制器

4.3 freemarker的servlet

4.4 加載 shiroFilter

4.5 加載 sitemesh

4.6 編碼過濾 避免出現亂碼

4.7 為下載下傳的檔案自動裝配相應的mime字尾

4.8 解決post亂碼

二,jdbc配置

配置資料庫連接配接池 dataSource

配置事物管理器 transactionManager(注入dataSource)

配置事物的傳播特性 transactionInterceptor(注入 transactionManager)

需要攔截的service(注入 transactionInterceptor)

配置sqlsessionfactory (注入dataSource)

配置mapper掃描包

三,freemarker

配置freeMarker的模闆路徑

配置freeMarker視圖解析器

在web.xml中配置freemark的servlet

在FreeMarker架構中使用Shiro的Tag标簽

ShiroFreeMarkerConfigurer繼承FreeMarkerConfigurer

在springmvc.xml中配置 如上第一步

第三步

引用

使用

@shiro.hasAnyRoles>

四,ehcache(緩存)

啟用緩存

聲明一個緩存管理器

spring對ehcache的緩存工廠支援

這裡要加載(classpath:ehcache/ehcache-context.xml)

掃描包

使用

在接口中通過

@Cacheable(value = "homeCache", key = "'menuTree'")來使用 (這裡注解中value=”homeCache”與ehcache-context.xml中的cache名稱屬性值一緻。)

五,shiro權限管理

詞語了解--角色(role),權限(permission),資源(resource),使用者(user)這四者的關系

簡單了解為使用者有不同的角色,而角色對應着權限,而權限可以對資源進行增删改查等操作。

配置

配置shiro的過濾器工廠類,id-shiroFilter要和我們在web.xml中配置的過濾器一緻

配置權限管理器

在web.xml中配置shiro 安全過濾器

使用

3.1 攔截請求的配置,對不同類的url進行不同的角色或者權限過濾

authc:該過濾器下的頁面必須驗證後才能通路

anyroles:隻有此角色才能通路

rulepermission:對通路的頁面進行角色和權限驗證

/logout = logout

/home = authc,anyroles[hrteacher]

/mycenter = authc

/authenticate = anon

/sys/** = path

/hrteacher/** = authc,rulepermission,path

/teacher/** = authc,anyroles[teacher],path

3.2 public class CustomeRealm extends AuthorizingRealm 自定義一個類,繼承AuthorizingRealm

protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) 授權

protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException 登入驗證

六,org.dozer.DozerBeanMapper

主要用以節點資料整合,是一個JavaBean映射工具庫。它支援簡單的屬性映射,複雜類型映射,雙向映射,隐式顯式的映射,以及遞歸映射

加載classpath:mapper/dozer-bean-mappings.xml;