Skip to content

This is a empty project build with SpringMVC+Spring+Mybatis+Maven+Shiro

Notifications You must be signed in to change notification settings

zZcoming/EmptySSM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tips: 启动项目后,welcome-file的链接即为测试用例

  1. 部署maven web项目
    <dependency>
    	<groupId>javax.servlet</groupId>
    	<artifactId>javax.servlet-api</artifactId>
    	<version>3.1.0</version>
    	<scope>provided</scope>
    </dependency>
    <dependency>
    	<groupId>javax.servlet</groupId>
    	<artifactId>jsp-api</artifactId>
    	<version>2.0</version>
    	<scope>provided</scope>
    </dependency>
    <dependency>
    	<groupId>javax.servlet</groupId>
    	<artifactId>jstl</artifactId>
    	<version>1.2</version>
    	<scope>provided</scope>
    </dependency>
    
    • 配置jdk版本,在build->plugins节点中添加:
     <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
             <source>1.7</source>
             <target>1.7</target>
         </configuration>
     </plugin>
    
  2. 整合spring
  3. 整合log4j
  4. 配置dataSource
     <!-- druid -->
     <dependency>
     	<groupId>com.alibaba</groupId>
     	<artifactId>druid</artifactId>
     	<version>1.0.7</version>
     </dependency>
    
  5. 整合mybatis

    在此,应完成的有:

    1. 事务管理
    2. 扫描mapper包
  6. 整合mybatis-generator

    mybatis-spring的版本换成1.3.0,否则会报错: java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L

  7. 用junit测试一下
  8. 整合springMVC
  9. 整合Shiro
    • 添加Shiro依赖
     <dependency>
     	<groupId>org.apache.shiro</groupId>
     	<artifactId>shiro-web</artifactId>
     	<version>1.2.4</version>
     </dependency>
     <dependency>
     	<groupId>org.apache.shiro</groupId>
     	<artifactId>shiro-spring</artifactId>
     	<version>1.2.4</version>
     </dependency>
    
    • web.xml中配置Shiro拦截器
     <!-- Shiro filter -->
     <filter>
     	<filter-name>shiroFilter</filter-name>
     	<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
     	<init-param>
     		<param-name>targetFilterLifecycle</param-name>
     		<param-value>true</param-value>
     	</init-param>
     </filter>
     <filter-mapping>
     	<filter-name>shiroFilter</filter-name>
     	<url-pattern>/*</url-pattern>
     </filter-mapping>
    
    • applicationContext.xml中配置Shiro
    <!-- Shiro start-->
     <bean id="myRealm" class="cn.jxnu.realm.UserRealm" />
    
     <!-- 安全管理器 -->
     <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
     	<property name="realm" ref="myRealm" />
     </bean>
    
     <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
     <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
    
     <!-- Shiro过滤器 -->
     <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
     	<!-- Shiro的核心安全接口,这个属性是必须的 -->
     	<property name="securityManager" ref="securityManager" />
     	<!-- 身份认证失败,则跳转到登录页面的配置 -->
     	<property name="loginUrl" value="/user/login" />
     	<!-- 登录成功,跳转到成功页面 -->
     	<!-- <property name="successUrl" value="/success"/> -->
     	<!-- 权限认证失败,则跳转到指定页面 -->
     	<property name="unauthorizedUrl" value="/user/login?msg=unlogin or unauthorized" />
     	<!-- Shiro连接约束配置,即过滤链的定义 -->
     	<property name="filterChainDefinitions">
     		<value>
     			/ = anon
     			/user/login = anon
     			/user/home = roles[teacher]
     			/user/save = perms["user:create"]
     			/** = authc
     		</value>
     	</property>
     </bean>
     <!-- Shiro end -->
    
    • 顺便把登录之类的功能补全一下,还有role和permission的数据库之类的(连带着generatorConfig.xml也要增加),index.jsp也增加几个例子
  10. EncodingFilter
  1. 集成SiteMesh(拼接jsp)

About

This is a empty project build with SpringMVC+Spring+Mybatis+Maven+Shiro

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages