1. 程式人生 > >Maven搭建Spring+SpringMVC+Mybatis+Shiro專案詳解

Maven搭建Spring+SpringMVC+Mybatis+Shiro專案詳解

最近新換了一臺機子,這次主要框架使用spring+SpringMVC+Mybatis+Shiro。專案持久層使用Mybatis3.3.0,控制層使用SpringMVC4.3.6,使用Spring4.3.6管理控制器,使用Shiro1.2.4許可權管理器,資料庫連線池使用druid資料來源,該項資料庫暫使用MySQL5.6。環境是win10 64位 jdk1.8 tomcat8.5 Maven 3.5 

2、修改pom.xml新增對應的包依賴 
這兒將全部使用的Maven依賴貼出了,對應什麼作用上面都有解釋,如下:pom.xml

<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.0</modelVersion> <groupId>com.peng</groupId> <artifactId>ssms</artifactId> <packaging>war</packaging
>
<version>0.0.1-SNAPSHOT</version> <name>ssms Maven Webapp</name> <url>http://maven.apache.org</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>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136

3、引入Spring,Springmvc以及spring與mybatis整合並配置相關屬性 
在src/main/resources建立spring,springmvc的配置檔案,這裡建立了spring-mybatis.xml,spring-mvc.xml,資訊如下:

<?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:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/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="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="mapperLocations" value="classpath:com/peng/entity/mapper/*.xml" />
    </bean>
    <!-- 掃描Mapper 配置檔案-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <
            
           

相關推薦

Maven搭建Spring+SpringMVC+Mybatis+Shiro專案

最近新換了一臺機子,這次主要框架使用spring+SpringMVC+Mybatis+Shiro。專案持久層使用Mybatis3.3.0,控制層使用SpringMVC4.3.6,使用Spring4.3.6管理控制器,使用Shiro1.2.4許可權管理器,資料庫連線池使

利用Maven搭建Spring+SpringMVC+Mybatis框架專案(二)

上次寫到將Spring和Mybatis整合到了一起,這次便將SpringMVC整合進去,SpringMVC只負責controller和頁面之間的跳轉,也就是隻負責和使用者互動 3.2 整合SpringMVC框架 3.2.1 建立spring-mvc.xml

基於maven搭建spring+springMVC+mybatis(SSM)框架專案

一.簡介 這篇文章是記錄我自己手動搭建基於maven的SSM(spring+springMVC+mybatis)框架專案的整個過程,目的是為了加深印象和方便以後查閱以及整理思路。 二.開發環境準備 (1)系統:Windows10(專業版) (2)eclispe版本:Eclipse J

在IntelliJ IDEA上搭建Spring+SpringMVC+Mybatis+Shiro環境搭建(一)

IntelliJ IDEA 下載地址:http://www.jetbrains.com/idea/ 都是最新版本的,只要破解一個版本,其他版本可以共用,具體參考百度O(∩_∩)O Maven Reposity Maven倉庫地址:http://mvnrepository.c

使用idea搭建Maven+SSM(Spring+SpringMVC+Mybatis)框架(一、使用Maven創建新工程)

post eight 9.png 圖片 tis 本地包 end pen nbsp 一、新建Maven項目 1、如圖創建簡單java web application。 2、如圖填寫組織唯一標識和項目唯一標識 3、如圖照做 4、點擊finish即可完成項目創建,如圖為創建

基於Maven工具搭建Spring+SpringMVC++MyBatis(ssm)框架步驟

目錄 1.使用Ecplise建立Maven工程: 2.構建SSM框架 3.日誌資訊:log4j 4.應用例項:使用者登入 5 資料庫MySQL 1.使用Ecplise建立Maven工程: 1.1 File -> New -> Other,在New視

簡單的SSM(Spring+SpringMVC+Mybatis專案搭建

SSM(Spring+SpringMVC+MyBatis)框架集由Spring、SpringMVC、MyBatis三個開源框架整合而成,常作為資料來源較簡單的web專案的框架。 spring是一個輕量級的控制反轉(IoC)和麵向切面(AOP)的容器框架。 SpringMV

4.IDEA用maven新建spring+springmvc+mybatis的web工程

測試 center -m 支持 書寫 size poj web 訪問 4.IDEA新建maven+springmvc的web工程 1.新建web工程 2.導入框支持 3.配置web.xml 4.配置spring.xml 5.配置spring-mvc.xml 6.配置spri

使用maven整合spring+springmvc+mybatis

cti 監聽 package 基於接口 mysql 5.7 spring 整合 rri ext inter 使用maven整合spring+springmvc+mybatis 開發環境:     1.  jdk1.8     2.  eclipse4.7.0 (Oxygen

練習搭建spring+springmvc+mybatis實現java web登陸

  關於spring、springmvc、mybatis的相關資料需要提前瞭解一下。我也只是初學者,就不介紹了。 我使用的是idea 如果有用eclipse也是類似 第一步我是用的maven來引進外部包,它很好用省得你到處去下載包。 新建一個maven專案 修改p

mavenspring+springmvc+mybatis整合詳細配置

首先配置mybatis,可以參考這篇部落格的前期基礎配置使用。 https://blog.csdn.net/qq_41520636/article/details/84146699 下面配置結構:  需要的jar,在pom.xml中引入 <!--統一j

(實用篇)一步步搭建Spring+SpringMVC+MyBatis(SSM)框架

一、前言 本篇內容是培訓作業的第一個任務,旨在搭建一個SSM框架,做一個HTML頁面,能查詢,能插入資料(新建使用者)、登陸。實現的功能最為基礎,但是要求所有程式碼均為手寫,不能使用Mybatis 自動生成mapping和dao。由於此框架是後面一系列任務的基礎,所以,還是

Maven 搭建spring boot多模組專案

轉自:https://segmentfault.com/a/1190000005020589 備註:所有專案都在idea中建立 1.idea建立maven專案(Project) 1-1: file > new > project 輸入 groupId和a

spring+springmvc+mybatis+shiro+ehcache整合demo

實際使用shiro的時候大部分都是和spring等框架結合使用,主要就是配置web.xml將shiro的filter和spring容器bean的filter關聯起來,生命週期由servlet容器來控制,然後配置shiro的spring的xml檔案,其中主要配置s

一步一步教你搭建Spring+SpringMVC+Mybatis

Spring+SpringMVC+Mybatis 最近剛玩CDSN,上網轉了轉,發現網上有許多SSM框架架構的相關教程,不過都比較簡短,可能小萌新看懂需要花費很多腦力和時間,所以本人就決定寫一篇所有人都能輕鬆看懂的教程,還望大家多多支援hhh~~~ 如果你是

使用HikariCP資料庫連線池搭建Spring-Boot+Mybatis專案

前言 Springboot讓Java開發更加美好,更加簡潔,更加簡單。本節主要講的是使用Hikari資料庫連線池搭建Spring-Boot+Mybatis專案。 這裡各位肯定會有一個問題:為什麼我們要選擇Hikari的資料庫連線池了,而不選擇C3P0/DBCP這些成熟的資

Maven搭建spring boot多模組專案打jar war zip 包方式

Spring boot 父專案聚合以下模組,下圖是parent.pom:其中controller是web模組,各個模組的依賴關係如下:由於spring boot 內嵌了servlet容器,而且提供了專案的java -jar啟動方式,所以可以把所有模組都打為jar包形式:con

SSM框架搭建(Spring+SpringMVC+MyBatis)

SSM框架搭建 目錄 一丶概述介紹       1.SSM介紹 二丶需求分析       搭建SSM框架 三丶步驟分析以及操作 一丶概述介紹        SSM(Spring+Sp

超級詳細的新手在Idea中使用maven配置Spring+springmvc+mybatis(SSM)框架步驟

首先呢我們需要準備一些東西:tomact建議用最新的,當然沒有最新的也用tomact8以上。jdk:1.8,idea2018年版,maven是用的3.0以上。 下面開始詳細描述步驟: 一:建立maven-web專案 1.點選新建一個project,idea

在eclipse建立spring+springMVC+Mybatis專案

現在使用maven構建的專案會讓我們省去jar包的匯入和每個工程都匯入數量較多jar包的苦惱,特別是在團隊開發中,我們應該保證我們使用的jar包的版本一致,使用maven之後,我們僅需要保證pom.xml檔案一致。他會自己按<dependency>節點中配置的資