2、修改l添加对应的包依赖
这⼉将全部使⽤的Maven依赖贴出了,对应什么作⽤上⾯都有解释,如下:l
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ssms Maven Webapp</name>
<url></url>
<properties>
<spring.version>4.3.6.RELEASE</spring.version> <mysql.version>5.1.10</mysql.version>
<druid.version>1.0.12</druid.version>
<log4j.version>1.2.17</log4j.version>
<mybatis.version>3.3.0</mybatis.version>
<shiro.version>1.2.4</shiro.version>
<jstl.version>1.2</jstl.version>
</properties>
<dependencies>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 事务 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 数据库驱动 mysql driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- ⽇志 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId&batis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<dependency>
<groupId&batis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency>
<!-- shiro -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>${shiro.version}</version>
</dependency>
<!-- 添加jtl⽀持 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<!-- 添加Servlet⽀持 -->
<!-- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency> -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>ssms</finalName>
<!-- <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins> -->
</build>
</project>
3、引⼊Spring,Springmvc以及spring与mybatis集成并配置相关属性
在src/main/resources创建spring,springmvc的配置⽂件,这⾥创建了l,l,信息如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:context="/schema/context"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans-4.3.xsd
/schema/context
/schema/context/spring-context-4.3.xsd">
<!-- 导⼊配置⽂件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- druid 数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 扫描mybatis 配置⽂件-->
<bean name="sqlSessionFactory" class="batis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:com/peng/entity/mapper/*.xml" />
</bean>
<!-- 扫描Mapper 配置⽂件-->
<bean class="batis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.peng.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:context="/schema/context"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans-4.3.xsd
/schema/context
/schema/context/spring-context-4.3.xsd">
<!-- 使⽤spring组件扫描@controller -->
<context:component-scan base-package="com.ller"/>
<!-- 通过annotation-driven可以替代下边的处理器映射器和适配器 -->
<!-- ⾃动注解 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
<!-- 视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
4、引⼊Mybatis并配置数据连接池等信息
在src/main/resources创建配置连接池配置信息在jdbc.properties中,如下:
jdbc.sql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssms?useUnicode=true&characterEncoding=UTF-8 jdbc.username=root
jdbc.password=root
5、引⼊⽇志配置log4j打印信息到后台
在src/main/resources创建log4j.properties,如下:
#定义LOG输出级别
#定义⽇志输出⽬的地为控制台
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=system.out
#可以灵活地指定⽇志输出格式,下⾯⼀⾏是指定具体的格式 %d [%t]%-5p [%c] - %m%n
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n
#⽂件⼤⼩到达指定尺⼨的时候产⽣⼀个新的⽂件
log4j.appender.File = org.apache.log4j.RollingFileAppender
#指定输出⽬录
log4j.appender.File.File = d:/logs/ssms.log
#定义⽂件最⼤⼤⼩
log4j.appender.File.MaxFileSize = 10MB
# 输出所以⽇志,如果换成DEBUG表⽰输出DEBUG以上级别⽇志
log4j.appender.File.Threshold = ALL
log4j.appender.File.layout = org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n 6、l 配置spring,对springmvc的⽀持,shiro的filter 如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="/2001/XMLSchema-instance"
xmlns="java.sun/xml/ns/javaee"
xsi:schemaLocation="java.sun/xml/ns/javaee
java.sun/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ssms</display-name>
shiro安全框架<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>l,l</param-value>
</context-param>
<listener>
<listener-class>org.t.ContextLoaderListener</listener-class>
</listener>
<!-- 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>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>shiroFilter</param-value>
</init-param>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论