快速构建spring boot 微服务工程
2017-03-01 00:12
435 查看
pom.xml如下:
创建配置文件
其中log4j2.properties为日志配置文件
application.properties为主配置文件
这里用properties配置文件方式配置,大家也可以用yml配置文件方式配置,看大家喜好
其余三个则对应环境
主配置文件:
spring.profiles.active=dev
其中 active代表对应的环境
其余环境的配置文件(这里只贴dev环境)
发布服务启动类:
使用请求访问服务:
启动服务
接下来访问我们的服务
访问成功
boot作为一个为服务框架很好作为springmvc的替代品,总体来说也很简单;总之spring的全家桶基本上每个子项目都很好的支持spring框架,例如Spring Security代替shiro;
先写到这里吧,有空会写有关spring boot 的其他内容
<?xml version="1.0" encoding="UTF-8"?> <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>org.gvinaxu.spring.boot</groupId> <artifactId>SpringBootDemo</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>A Camel Route</name> <properties> <mybatis.version>1.1.1</mybatis.version> <druid.version>1.0.7</druid.version> <start-class>org.gvinaxu.springboot.demo.Application</start-class> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.14</version> <scope>provided</scope> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.21</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!--替换tomcat为jetty --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId 4000 >org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <!-- 数据库 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.5</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- log4j2 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.6.2</version> </dependency> <dependency> <groupId>com.github.tobato</groupId> <artifactId>fastdfs-client</artifactId> <version>1.25.2-RELEASE</version> <exclusions> <exclusion> <artifactId>logback-classic</artifactId> <groupId>ch.qos.logback</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.7.3</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-redis</artifactId> </dependency> </dependencies> <!-- build --> <build> <resources> <resource> <directory>src/main/java</directory> <!-- <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> --> </resource> <resource> <directory>src/main/resources</directory> <!-- <excludes> <exclude>*</exclude> </excludes> --> </resource> </resources> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>utf-8</encoding> <compilerArguments> <extdirs>library</extdirs> </compilerArguments> </configuration> <version>2.3.2</version> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <!--执行器 mvn assembly:assembly --> <execution> <id>make-zip</id><!--名字任意 --> <phase>package</phase><!-- 绑定到package生命周期阶段上 --> <goals> <goal>single</goal><!-- 只运行一次 --> </goals> <configuration> <descriptors> <!--描述文件路径 --> <descriptor>src/main/assembly.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
创建配置文件
其中log4j2.properties为日志配置文件
application.properties为主配置文件
这里用properties配置文件方式配置,大家也可以用yml配置文件方式配置,看大家喜好
其余三个则对应环境
主配置文件:
spring.profiles.active=dev
其中 active代表对应的环境
server.display-name: org-gvinaxu-spring server.port:6666 server.contextPath=/boot #ConfigurableEnvironment spring.profiles.active=dev #configure 日志配置文件 spring.logging.config=classpath:log4j2.properties #configure fastdfs fdfs.soTimeout=1500 fdfs.connectTimeout=600 fdfs.thumbImage.width=150 fdfs.thumbImage.height=150 #fdfs.trackerList[0]=215.128.18.152:22122 fdfs.trackerList[0]=192.168.1.20:22122 spring.jmx.enabled=false spring.http.multipart.maxFileSize=4Mb spring.http.multipart.maxRequestSize=4Mb multipart.maxFileSize=4Mb multipart.maxRequestSize=4Mb
其余环境的配置文件(这里只贴dev环境)
spring.datasource.name=DEMO spring.datasource.url=jdbc:mysql://localhost:3306/test spring.datasource.username=root spring.datasource.password=3368 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.filters=mergeStat spring.datasource.maxActive=500 spring.datasource.initialSize=0 spring.datasource.maxWait=60000 spring.datasource.minIdle=0 spring.datasource.timeBetweenEvictionRunsMillis=60000 spring.datasource.minEvictableIdleTimeMillis=25200000 spring.datasource.testWhileIdle=true spring.datasource.testOnBorrow=false spring.datasource.testOnReturn=false spring.datasource.poolPreparedStatements=true spring.datasource.maxOpenPreparedStatements=20 spring.datasource.removeAbandoned=true spring.datasource.removeAbandonedTimeout=1800 spring.datasource.logAbandoned=true ##redis configure # REDIS (RedisProperties) spring.redis.database=0 # Redis\u670D\u52A1\u5668\u5730\u5740 spring.redis.host=192.168.1.3 spring.redis.port=6379 spring.redis.password=foobared spring.redis.pool.max-active=8 spring.redis.pool.max-wait=-1 spring.redis.pool.max-idle=8 spring.redis.pool.min-idle=0 spring.redis.timeout=0
发布服务启动类:
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.context.annotation.ComponentScan; import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication @EnableTransactionManagement @ComponentScan(basePackages={"org.gvinaxu.springboot"}) @ServletComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
使用请求访问服务:
@RestController @RequestMapping(value = "/demo") public class DemoController { @PostMapping(value = "/post") public String post(HttpServletRequest request, HttpServletResponse response){ return "HelloWorld"; } @GetMapping(value = "/get") public String get(HttpServletRequest request, HttpServletResponse response){ return "HelloWorld"; } }
启动服务
接下来访问我们的服务
访问成功
boot作为一个为服务框架很好作为springmvc的替代品,总体来说也很简单;总之spring的全家桶基本上每个子项目都很好的支持spring框架,例如Spring Security代替shiro;
先写到这里吧,有空会写有关spring boot 的其他内容
相关文章推荐
- Spring Cloud Spring Boot mybatis分布式微服务云架构(二)使用Intellij中的Spring Initializr来快速构建Spring Boot/Cloud工程
- SpringBoot快速构建微服务架构体系
- Spring Cloud Spring Boot mybatis分布式微服务云架构(二)使用Intellij中的Spring Initializr来快速构建Spring Boot/Cloud工程
- SpringBoot揭秘:快速构建微服务体系
- 使用 Spring Boot 快速构建应用服务
- 使用gradle构建springboot工程的以及部署springboot到linux服务
- 构建微服务:快速搭建Spring Boot项目
- Spring Cloud Spring Boot mybatis分布式微服务云架构(二)使用Intellij中的Spring Initializr来快速构建Spring Boot/Cloud工程
- JAVAEE——SpringBoot入门:简介、微服务、环境准备、helloworld与探究、快速构建项目
- SpringBoot构建微服务实战 之 服务注册的快速打包
- 01.Spring Cloud学习笔记之使用IDEA+Spring Boot快速构建Rest服务
- 详解SpringBoot 使用Spring Initializr 快速构建工程(官方推荐)
- 快速构建Spring boot项目(功能是检测访问页面的设备)
- springboot 构建微服务设置远程调试
- 使用Spring Boot快速构建应用
- 使用Spring Boot快速构建应用
- 使用 Spring Boot 快速构建 Spring 框架应用---学习笔记
- 使用Spring Boot快速构建应用
- 使用Spring Boot快速构建应用