本次建立項目分成下面幾個步驟介紹
(1)建立springboot項目;
(2)整合mybatis,搭建資料通路層架構
(3)整合shiro搭建權限驗證架構;
(4)自動生成代碼;
(5)整合logger搭建日志架構
建立springboot項目
準備環境
1、jdk1.8及以上;
2、maven 3.6.1;
3、開發工具:本人使用的是idea,也可以使用eclipse;
開始搭建
(一)、打開file–>New–>Project 建立一個項目;
(二)、選擇Spring Initialize,點選next;
(三)、首先勾上Web下面的Spring Web,接着勾上SQl下面的MySQL Driver和Mybatis Framework,然後點選next
(4)、選擇finish完成項目的建立;
(5)、springboot項目已建立完畢,由于我們未配置資料庫通路層資訊,是以改一下springboot啟動類SpringbootApplication.java,不建立DataSourceAutoConfiguration.class和DataSourceTransactionManagerAutoConfiguration.class兩個類,如下所示
package com.itwopqq.booting;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class })
public class BootingApplication {
public static void main(String[] args) {
SpringApplication.run(BootingApplication.class, args);
}
}
(6)、接下來我們啟動項目,我們可以看到springboot項目已經啟動完畢,下一章我們将介紹如何整和資料通路層;
/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:52023,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:/Users/fanzhen/Library/Caches/IntelliJIdea2019.1/captureAgent/debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/tools.jar:/Users/fanzhen/Documents/ideaworkspaces/booting/target/classes:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot-starter-web/2.2.6.RELEASE/spring-boot-starter-web-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot-starter/2.2.6.RELEASE/spring-boot-starter-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot/2.2.6.RELEASE/spring-boot-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot-autoconfigure/2.2.6.RELEASE/spring-boot-autoconfigure-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot-starter-logging/2.2.6.RELEASE/spring-boot-starter-logging-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/Users/fanzhen/Documents/local-repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/Users/fanzhen/Documents/local-repository/org/apache/logging/log4j/log4j-to-slf4j/2.12.1/log4j-to-slf4j-2.12.1.jar:/Users/fanzhen/Documents/local-repository/org/apache/logging/log4j/log4j-api/2.12.1/log4j-api-2.12.1.jar:/Users/fanzhen/Documents/local-repository/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar:/Users/fanzhen/Documents/local-repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/fanzhen/Documents/local-repository/org/yaml/snakeyaml/1.25/snakeyaml-1.25.jar:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot-starter-json/2.2.6.RELEASE/spring-boot-starter-json-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/com/fasterxml/jackson/core/jackson-databind/2.10.3/jackson-databind-2.10.3.jar:/Users/fanzhen/Documents/local-repository/com/fasterxml/jackson/core/jackson-annotations/2.10.3/jackson-annotations-2.10.3.jar:/Users/fanzhen/Documents/local-repository/com/fasterxml/jackson/core/jackson-core/2.10.3/jackson-core-2.10.3.jar:/Users/fanzhen/Documents/local-repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.10.3/jackson-datatype-jdk8-2.10.3.jar:/Users/fanzhen/Documents/local-repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.10.3/jackson-datatype-jsr310-2.10.3.jar:/Users/fanzhen/Documents/local-repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.10.3/jackson-module-parameter-names-2.10.3.jar:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot-starter-tomcat/2.2.6.RELEASE/spring-boot-starter-tomcat-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.33/tomcat-embed-core-9.0.33.jar:/Users/fanzhen/Documents/local-repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.33/tomcat-embed-el-9.0.33.jar:/Users/fanzhen/Documents/local-repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.33/tomcat-embed-websocket-9.0.33.jar:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot-starter-validation/2.2.6.RELEASE/spring-boot-starter-validation-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar:/Users/fanzhen/Documents/local-repository/org/hibernate/validator/hibernate-validator/6.0.18.Final/hibernate-validator-6.0.18.Final.jar:/Users/fanzhen/Documents/local-repository/org/jboss/logging/jboss-logging/3.4.1.Final/jboss-logging-3.4.1.Final.jar:/Users/fanzhen/Documents/local-repository/com/fasterxml/classmate/1.5.1/classmate-1.5.1.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-web/5.2.5.RELEASE/spring-web-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-beans/5.2.5.RELEASE/spring-beans-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-webmvc/5.2.5.RELEASE/spring-webmvc-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-aop/5.2.5.RELEASE/spring-aop-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-context/5.2.5.RELEASE/spring-context-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-expression/5.2.5.RELEASE/spring-expression-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/mybatis/spring/boot/mybatis-spring-boot-starter/2.1.2/mybatis-spring-boot-starter-2.1.2.jar:/Users/fanzhen/Documents/local-repository/org/springframework/boot/spring-boot-starter-jdbc/2.2.6.RELEASE/spring-boot-starter-jdbc-2.2.6.RELEASE.jar:/Users/fanzhen/Documents/local-repository/com/zaxxer/HikariCP/3.4.2/HikariCP-3.4.2.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-jdbc/5.2.5.RELEASE/spring-jdbc-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-tx/5.2.5.RELEASE/spring-tx-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/mybatis/spring/boot/mybatis-spring-boot-autoconfigure/2.1.2/mybatis-spring-boot-autoconfigure-2.1.2.jar:/Users/fanzhen/Documents/local-repository/org/mybatis/mybatis/3.5.4/mybatis-3.5.4.jar:/Users/fanzhen/Documents/local-repository/org/mybatis/mybatis-spring/2.0.4/mybatis-spring-2.0.4.jar:/Users/fanzhen/Documents/local-repository/mysql/mysql-connector-java/8.0.19/mysql-connector-java-8.0.19.jar:/Users/fanzhen/Documents/local-repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-core/5.2.5.RELEASE/spring-core-5.2.5.RELEASE.jar:/Users/fanzhen/Documents/local-repository/org/springframework/spring-jcl/5.2.5.RELEASE/spring-jcl-5.2.5.RELEASE.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar" com.itwopqq.booting.BootingApplication
Connected to the target VM, address: '127.0.0.1:52023', transport: 'socket'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-03-29 15:17:05.611 INFO 1564 --- [ main] com.itwopqq.booting.BootingApplication : Starting BootingApplication on fanzhendeMacBook-Air.local with PID 1564 (/Users/fanzhen/Documents/ideaworkspaces/booting/target/classes started by fanzhen in /Users/fanzhen/Documents/ideaworkspaces/booting)
2020-03-29 15:17:05.615 INFO 1564 --- [ main] com.itwopqq.booting.BootingApplication : No active profile set, falling back to default profiles: default
2020-03-29 15:17:07.106 INFO 1564 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-29 15:17:07.122 INFO 1564 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-29 15:17:07.122 INFO 1564 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-03-29 15:17:07.228 INFO 1564 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-29 15:17:07.228 INFO 1564 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1538 ms
2020-03-29 15:17:07.489 INFO 1564 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-29 15:17:07.739 INFO 1564 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-29 15:17:07.745 INFO 1564 --- [ main] com.itwopqq.booting.BootingApplication : Started BootingApplication in 2.641 seconds (JVM running for 7.329)