站点工具


服务器技术:微服务:基于maven的springboot_mybatis_druid_swagger2_mybatis-generator框架环境搭建

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
服务器技术:微服务:基于maven的springboot_mybatis_druid_swagger2_mybatis-generator框架环境搭建 [2018/06/14 16:48]
admin
服务器技术:微服务:基于maven的springboot_mybatis_druid_swagger2_mybatis-generator框架环境搭建 [2018/09/10 18:02] (当前版本)
行 56: 行 56:
 &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​lt;​artifactId&​gt;&​nbsp;​mysql-connector-java&​lt;/​artifactId&​gt;​ &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​lt;​artifactId&​gt;&​nbsp;​mysql-connector-java&​lt;/​artifactId&​gt;​
 &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​lt;​version&​gt;&​nbsp;​5.0.5&​lt;/​version&​gt;​ &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​lt;​version&​gt;&​nbsp;​5.0.5&​lt;/​version&​gt;​
-&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​lt;/​dependency&​gt;</​pre><​p style="">​其中spring-boot-devtools不是必须,只是如果你想在运行的时候,修改了代码能自动更新,而不用手动重启,就需要加上</​p><​h5 style="">​三、添加Applcation类</​h5><​p style="">​这个就是程序的入口类了,代码如下</​p><​p>​Java</​p><​pre class="​ language-java"​ style="​font-family:​Consolas,​Monaco,&#​39;​Andale Mono&#​39;,&#​39;​Ubuntu Mono&#​39;,​monospace;​ font-size:​0.9em;​ margin-top:​0.5em;​ margin-bottom:​0.5em;​ border:1px solid rgb(227,​237,​243);​ width:​1178px;​ padding:​1em;​ overflow:​auto;​ color:​rgb(248,​248,​242);​ word-spacing:​normal;​ word-break:​normal;​ word-wrap:​normal;​ line-height:​1.5;​ background:​rgb(39,​40,​34)">​package&​nbsp;​wang.raye.springboot;​import&​nbsp;​org.mybatis.spring.annotation.MapperScan;​import&​nbsp;​org.springframework.boot.SpringApplication;​import&​nbsp;​org.springframework.boot.autoconfigure.SpringBootApplication;​import&​nbsp;​org.springframework.boot.web.servlet.ServletComponentScan;​import&​nbsp;​org.springframework.boot.web.support.SpringBootServletInitializer;/​**+&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​lt;/​dependency&​gt;</​pre><​p style="">​其中spring-boot-devtools不是必须,只是如果你想在运行的时候,修改了代码能自动更新,而不用手动重启,就需要加上</​p><​h5 style="">​三、添加Applcation类</​h5><​p style="">​这个就是程序的入口类了,代码如下</​p><​p>​Java</​p><​pre class="​ language-java"​ style="​font-family:​Consolas,​Monaco,&#​39;​Andale Mono&#​39;,&#​39;​Ubuntu Mono&#​39;,​monospace;​ font-size:​0.9em;​ margin-top:​0.5em;​ margin-bottom:​0.5em;​ border:1px solid rgb(227,​237,​243);​ width:​1178px;​ padding:​1em;​ overflow:​auto;​ color:​rgb(248,​248,​242);​ word-spacing:​normal;​ word-break:​normal;​ word-wrap:​normal;​ line-height:​1.5;​ background:​rgb(39,​40,​34)">​package&​nbsp;​wang.raye.springboot;​ 
 +import&​nbsp;​org.mybatis.spring.annotation.MapperScan;​ 
 +import&​nbsp;​org.springframework.boot.SpringApplication;​ 
 +import&​nbsp;​org.springframework.boot.autoconfigure.SpringBootApplication;​ 
 +import&​nbsp;​org.springframework.boot.web.servlet.ServletComponentScan;​ 
 +import&​nbsp;​org.springframework.boot.web.support.SpringBootServletInitializer;​ 
 +/**
 &nbsp;* &nbsp;*
 &nbsp;* &nbsp;*
行 92: 行 98:
  
  
-debug:&​nbsp;​true</​pre><​p style="">​相信这个文件很容易看懂,首先server:​下面的port:​80这个是定义了运行的端口,之前说过spring boot内置了tomcat服务器,所以如果要使用内置的tomcat并且不想用8080端口,就需要在这里配置</​p><​p style="">​下面就是datasource的配置,这样不写进代码有个好处,那就是如果是给客户用的程序,可以很方便的修改数据库配置,而不用重新编译,当然如果你是打包jar我估计是要重新编译的,如果是war,那么就可以解压出来直接修改application.yml而不用重新编译了</​p><​p style="">​而debug:true就是说明当时是调试状态,这样就会输出很多log</​p><​h5 style="">​五、创建Druid数据源配置类</​h5><​p>​Java</​p><​pre class="​ language-java"​ style="​font-family:​Consolas,​Monaco,&#​39;​Andale Mono&#​39;,&#​39;​Ubuntu Mono&#​39;,​monospace;​ font-size:​0.9em;​ margin-top:​0.5em;​ margin-bottom:​0.5em;​ border:1px solid rgb(227,​237,​243);​ width:​1178px;​ padding:​1em;​ overflow:​auto;​ color:​rgb(248,​248,​242);​ word-spacing:​normal;​ word-break:​normal;​ word-wrap:​normal;​ line-height:​1.5;​ background:​rgb(39,​40,​34)">​package&​nbsp;​wang.raye.springboot.config;​import&​nbsp;​java.sql.SQLException;​import&​nbsp;​javax.sql.DataSource;​import&​nbsp;​org.springframework.boot.bind.RelaxedPropertyResolver;​import&​nbsp;​org.springframework.context.EnvironmentAware;​import&​nbsp;​org.springframework.context.annotation.Bean;​import&​nbsp;​org.springframework.context.annotation.Configuration;​import&​nbsp;​org.springframework.core.env.Environment;​import&​nbsp;​org.springframework.transaction.annotation.EnableTransactionManagement;​import&​nbsp;​com.alibaba.druid.pool.DruidDataSource;​@Configuration@EnableTransactionManagement/​**+debug:&​nbsp;​true</​pre><​p style="">​相信这个文件很容易看懂,首先server:​下面的port:​80这个是定义了运行的端口,之前说过spring boot内置了tomcat服务器,所以如果要使用内置的tomcat并且不想用8080端口,就需要在这里配置</​p><​p style="">​下面就是datasource的配置,这样不写进代码有个好处,那就是如果是给客户用的程序,可以很方便的修改数据库配置,而不用重新编译,当然如果你是打包jar我估计是要重新编译的,如果是war,那么就可以解压出来直接修改application.yml而不用重新编译了</​p><​p style="">​而debug:true就是说明当时是调试状态,这样就会输出很多log</​p><​h5 style="">​五、创建Druid数据源配置类</​h5><​p>​Java</​p><​pre class="​ language-java"​ style="​font-family:​Consolas,​Monaco,&#​39;​Andale Mono&#​39;,&#​39;​Ubuntu Mono&#​39;,​monospace;​ font-size:​0.9em;​ margin-top:​0.5em;​ margin-bottom:​0.5em;​ border:1px solid rgb(227,​237,​243);​ width:​1178px;​ padding:​1em;​ overflow:​auto;​ color:​rgb(248,​248,​242);​ word-spacing:​normal;​ word-break:​normal;​ word-wrap:​normal;​ line-height:​1.5;​ background:​rgb(39,​40,​34)">​package&​nbsp;​wang.raye.springboot.config;​import&​nbsp;​java.sql.SQLException;​ 
 +import&​nbsp;​javax.sql.DataSource;​import&​nbsp;​org.springframework.boot.bind.RelaxedPropertyResolver;​ 
 +import&​nbsp;​org.springframework.context.EnvironmentAware;​ 
 +import&​nbsp;​org.springframework.context.annotation.Bean;​ 
 +import&​nbsp;​org.springframework.context.annotation.Configuration;​ 
 +import&​nbsp;​org.springframework.core.env.Environment;​ 
 +import&​nbsp;​org.springframework.transaction.annotation.EnableTransactionManagement;​ 
 +import&​nbsp;​com.alibaba.druid.pool.DruidDataSource;​@Configuration@EnableTransactionManagement 
 +/**
 &​nbsp;​*&​nbsp;​Druid的DataResource配置类 &​nbsp;​*&​nbsp;​Druid的DataResource配置类
 &​nbsp;​*&​nbsp;​@author&​nbsp;​Raye &​nbsp;​*&​nbsp;​@author&​nbsp;​Raye
行 123: 行 137:
 &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​} &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​}
 &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​return&​nbsp;​datasource;​ &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​return&​nbsp;​datasource;​
-&​nbsp;&​nbsp;&​nbsp;&​nbsp;​}}</​pre><​p style="">​主要是创建一个druid的DruidDataSource 返回并告诉spring boot这是一个bean</​p><​h5 style="">​六、创建Druid的监控servlet和filter</​h5><​p style=""><​span style="​font-weight:​700">​创建监控Servlet</​span></​p><​p>​Java</​p><​pre class="​ language-java"​ style="​font-family:​Consolas,​Monaco,&#​39;​Andale Mono&#​39;,&#​39;​Ubuntu Mono&#​39;,​monospace;​ font-size:​0.9em;​ margin-top:​0.5em;​ margin-bottom:​0.5em;​ border:1px solid rgb(227,​237,​243);​ width:​1178px;​ padding:​1em;​ overflow:​auto;​ color:​rgb(248,​248,​242);​ word-spacing:​normal;​ word-break:​normal;​ word-wrap:​normal;​ line-height:​1.5;​ background:​rgb(39,​40,​34)">​package&​nbsp;​wang.raye.springboot.config;​import&​nbsp;​javax.servlet.annotation.WebInitParam;​import&​nbsp;​javax.servlet.annotation.WebServlet;​import&​nbsp;​com.alibaba.druid.support.http.StatViewServlet;/​**+&​nbsp;&​nbsp;&​nbsp;&​nbsp;​}}</​pre><​p style="">​主要是创建一个druid的DruidDataSource 返回并告诉spring boot这是一个bean</​p><​h5 style="">​六、创建Druid的监控servlet和filter</​h5><​p style=""><​span style="​font-weight:​700">​创建监控Servlet</​span></​p><​p>​Java</​p><​pre class="​ language-java"​ style="​font-family:​Consolas,​Monaco,&#​39;​Andale Mono&#​39;,&#​39;​Ubuntu Mono&#​39;,​monospace;​ font-size:​0.9em;​ margin-top:​0.5em;​ margin-bottom:​0.5em;​ border:1px solid rgb(227,​237,​243);​ width:​1178px;​ padding:​1em;​ overflow:​auto;​ color:​rgb(248,​248,​242);​ word-spacing:​normal;​ word-break:​normal;​ word-wrap:​normal;​ line-height:​1.5;​ background:​rgb(39,​40,​34)">​package&​nbsp;​wang.raye.springboot.config;​ 
 +import&​nbsp;​javax.servlet.annotation.WebInitParam;​ 
 +import&​nbsp;​javax.servlet.annotation.WebServlet;​ 
 +import&​nbsp;​com.alibaba.druid.support.http.StatViewServlet;​ 
 +/**
 &​nbsp;​*&​nbsp;​Druid的Servlet &​nbsp;​*&​nbsp;​Druid的Servlet
 &​nbsp;​*&​nbsp;​@author&​nbsp;​Raye &​nbsp;​*&​nbsp;​@author&​nbsp;​Raye
行 132: 行 150:
 &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​@WebInitParam(name=&​quot;​loginUsername&​quot;,​value=&​quot;​Raye&​quot;​),//&​nbsp;​用户名 &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​@WebInitParam(name=&​quot;​loginUsername&​quot;,​value=&​quot;​Raye&​quot;​),//&​nbsp;​用户名
 &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​@WebInitParam(name=&​quot;​loginPassword&​quot;,​value=&​quot;​123456&​quot;​),//&​nbsp;​密码 &​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​@WebInitParam(name=&​quot;​loginPassword&​quot;,​value=&​quot;​123456&​quot;​),//&​nbsp;​密码
-&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​@WebInitParam(name=&​quot;​resetEnable&​quot;,​value=&​quot;​false&​quot;​)//&​nbsp;​禁用HTML页面上的“Reset&​nbsp;​All”功能})public&​nbsp;​class&​nbsp;​DruidStatViewServlet&​nbsp;​extends&​nbsp;​StatViewServlet&​nbsp;​{}</​pre><​p style=""><​span style="​font-weight:​700">​@WebServlet</​span>​表明这是一个Servlet,和之前Application中的@ServletComponentScan相对应使用&​nbsp;<​span style="​font-weight:​700">​创建filter</​span></​p><​p>​Java</​p><​pre class="​ language-java"​ style="​font-family:​Consolas,​Monaco,&#​39;​Andale Mono&#​39;,&#​39;​Ubuntu Mono&#​39;,​monospace;​ font-size:​0.9em;​ margin-top:​0.5em;​ margin-bottom:​0.5em;​ border:1px solid rgb(227,​237,​243);​ width:​1178px;​ padding:​1em;​ overflow:​auto;​ color:​rgb(248,​248,​242);​ word-spacing:​normal;​ word-break:​normal;​ word-wrap:​normal;​ line-height:​1.5;​ background:​rgb(39,​40,​34)">​package&​nbsp;​wang.raye.springboot.config;​import&​nbsp;​javax.servlet.annotation.WebFilter;​import&​nbsp;​javax.servlet.annotation.WebInitParam;​import&​nbsp;​com.alibaba.druid.support.http.WebStatFilter;​@WebFilter(filterName=&​quot;​druidWebStatFilter&​quot;,​urlPatterns=&​quot;/​*&​quot;,​initParams={+&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​@WebInitParam(name=&​quot;​resetEnable&​quot;,​value=&​quot;​false&​quot;​)//&​nbsp;​禁用HTML页面上的“Reset&​nbsp;​All”功能}) 
 +&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;&​nbsp;​public&​nbsp;​class&​nbsp;​DruidStatViewServlet&​nbsp;​extends&​nbsp;​StatViewServlet&​nbsp;​{}</​pre><​p style=""><​span style="​font-weight:​700">​@WebServlet</​span>​表明这是一个Servlet,和之前Application中的@ServletComponentScan相对应使用&​nbsp;<​span style="​font-weight:​700">​创建filter</​span></​p><​p>​Java</​p><​pre class="​ language-java"​ style="​font-family:​Consolas,​Monaco,&#​39;​Andale Mono&#​39;,&#​39;​Ubuntu Mono&#​39;,​monospace;​ font-size:​0.9em;​ margin-top:​0.5em;​ margin-bottom:​0.5em;​ border:1px solid rgb(227,​237,​243);​ width:​1178px;​ padding:​1em;​ overflow:​auto;​ color:​rgb(248,​248,​242);​ word-spacing:​normal;​ word-break:​normal;​ word-wrap:​normal;​ line-height:​1.5;​ background:​rgb(39,​40,​34)">​package&​nbsp;​wang.raye.springboot.config;​import&​nbsp;​javax.servlet.annotation.WebFilter;​import&​nbsp;​javax.servlet.annotation.WebInitParam;​import&​nbsp;​com.alibaba.druid.support.http.WebStatFilter;​@WebFilter(filterName=&​quot;​druidWebStatFilter&​quot;,​urlPatterns=&​quot;/​*&​quot;,​initParams={
 &​nbsp;&​nbsp;&​nbsp;&​nbsp;​@WebInitParam(name=&​quot;​exclusions&​quot;,​value=&​quot;​*.js,​*.gif,​*.jpg,​*.bmp,​*.png,​*.css,​*.ico,/​druid/​*&​quot;​)//&​nbsp;​忽略资源})/​** &​nbsp;&​nbsp;&​nbsp;&​nbsp;​@WebInitParam(name=&​quot;​exclusions&​quot;,​value=&​quot;​*.js,​*.gif,​*.jpg,​*.bmp,​*.png,​*.css,​*.ico,/​druid/​*&​quot;​)//&​nbsp;​忽略资源})/​**
 &​nbsp;​*&​nbsp;​Druid拦截器,用于查看Druid监控&​nbsp;​*&​nbsp;​@author&​nbsp;​Raye&​nbsp;​*&​nbsp;​@since&​nbsp;​2016年10月7日14:​59:​27 &​nbsp;​*&​nbsp;​Druid拦截器,用于查看Druid监控&​nbsp;​*&​nbsp;​@author&​nbsp;​Raye&​nbsp;​*&​nbsp;​@since&​nbsp;​2016年10月7日14:​59:​27
服务器技术/微服务/基于maven的springboot_mybatis_druid_swagger2_mybatis-generator框架环境搭建.1528966111.txt.gz · 最后更改: 2018/09/10 18:01 (外部编辑)