Maven+SSM+shiro的简单demo

搭建SSM框架

  • pom.xml 导入需要的jar包
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0modelVersion>
  <groupId>com.yuanjungroupId>
  <artifactId>SSMartifactId>
  <packaging>warpackaging>
  <version>0.0.1-SNAPSHOTversion>
  <name>SSM Maven Webappname>
  <url>http://maven.apache.orgurl>
 <properties>  
          
        <spring.version>4.0.2.RELEASEspring.version>  
          
        <mybatis.version>3.2.6mybatis.version>  
          
        <slf4j.version>1.7.7slf4j.version>  
        <log4j.version>1.2.17log4j.version>  
    properties>  
  
    <dependencies>  
        <dependency>
		    <groupId>junitgroupId>
		    <artifactId>junitartifactId>
		    <version>4.7version>
		    <scope>testscope>
		dependency>
          
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-coreartifactId>  
            <version>${spring.version}version>  
        dependency>  
  
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-webartifactId>  
            <version>${spring.version}version>  
        dependency>  
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-oxmartifactId>  
            <version>${spring.version}version>  
        dependency>  
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-txartifactId>  
            <version>${spring.version}version>  
        dependency>  
  
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-jdbcartifactId>  
            <version>${spring.version}version>  
        dependency>  
  
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-webmvcartifactId>  
            <version>${spring.version}version>  
        dependency>  
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-aopartifactId>  
            <version>${spring.version}version>  
        dependency>  
  
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-context-supportartifactId>  
            <version>${spring.version}version>  
        dependency>  
  
        <dependency>  
            <groupId>org.springframeworkgroupId>  
            <artifactId>spring-testartifactId>  
            <version>${spring.version}version>  
        dependency>  
          
        <dependency>  
            <groupId>org.mybatisgroupId>  
            <artifactId>mybatisartifactId>  
            <version>${mybatis.version}version>  
        dependency>  
          
        <dependency>  
            <groupId>org.mybatisgroupId>  
            <artifactId>mybatis-springartifactId>  
            <version>1.2.2version>  
        dependency>  
          
        <dependency>  
        	<scope>providedscope>
            <groupId>javaxgroupId>  
            <artifactId>javaee-apiartifactId>  
            <version>7.0version>  
        dependency>  
          
        <dependency>  
            <groupId>mysqlgroupId>  
            <artifactId>mysql-connector-javaartifactId>  
            <version>5.1.30version> 
        dependency>  
          
        <dependency>  
            <groupId>jstlgroupId>  
            <artifactId>jstlartifactId>  
            <version>1.2version>  
        dependency>  
          
          
        <dependency>  
            <groupId>log4jgroupId>  
            <artifactId>log4jartifactId>  
            <version>${log4j.version}version>  
        dependency>  
          
          
          
        <dependency>  
            <groupId>com.alibabagroupId>  
            <artifactId>fastjsonartifactId>  
            <version>1.1.41version>  
        dependency>  
  
  
        <dependency>  
            <groupId>org.slf4jgroupId>  
            <artifactId>slf4j-apiartifactId>  
            <version>${slf4j.version}version>  
        dependency>  
  
        <dependency>  
            <groupId>org.slf4jgroupId>  
            <artifactId>slf4j-log4j12artifactId>  
            <version>${slf4j.version}version>  
        dependency>  
          
        <dependency>
            <groupId>org.apache.shirogroupId>
            <artifactId>shiro-allartifactId>
            <version>1.3.2version>
        dependency>

		
		<dependency>
            <groupId>net.sf.ehcachegroupId>
            <artifactId>ehcacheartifactId>
            <version>2.8.2version>
        dependency>
		
    dependencies>  
  <build>
    <finalName>SSMfinalName>
     
		<resources>
			<resource>
				<directory>src/main/javadirectory>
				<includes>
					<include>**/*.propertiesinclude>
					<include>**/*.xmlinclude>
				includes>
				<filtering>falsefiltering>
			resource>
			<resource>
				<directory>src/main/resourcesdirectory>
				<includes>
					<include>**/*.propertiesinclude>
					<include>**/*.xmlinclude>
				includes>
				<filtering>falsefiltering>
			resource>
		resources>
  
  build>
 
project>

  • 配置spring相关配置文件
  • spring-mvc.xml 在原有ssm配置中增加shiro相关配置
  
<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:mvc="http://www.springframework.org/schema/mvc"  
    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-4.0.xsd">  
    <mvc:annotation-driven />

      
    <context:component-scan base-package="com.zyx.SSM.controller,com.shiro.controller" />  
      
    <bean id="mappingJacksonHttpMessageConverter"  
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>text/html;charset=UTF-8value>  
            list>  
        property>  
    bean>  
      
    <bean  
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
            <list>  
                <ref bean="mappingJacksonHttpMessageConverter" />   
            list>  
        property>  
    bean>  
      
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
          
        <property name="prefix" value="/" />  
        <property name="suffix" value=".jsp" />  
    bean>  

    
	<bean
		class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
		depends-on="lifecycleBeanPostProcessor">
		<property name="proxyTargetClass" value="true" />
	bean>

	
	
 
	
	<mvc:resources location="/js/" mapping="/js/**" />
	<mvc:resources location="/icon/" mapping="/icon/**" />
	<mvc:resources location="/" mapping="/**" />
beans>  

你可能感兴趣的:(shiro学习,ssm,shiro,maven)