SpringBoot学习:IDEA中快速搭建springboot项目
项目下载地址:http://download.csdn.net/detail/aqsunkai/9805821
(一)IDEA中创建maven web项目
创建好项目后设置项目的编译路径:
(二)引入spring-boot项目所需的jar包:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot.version>1.5.2.RELEASE</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<!-- spring-web, spring-webmvc Spring WebMvc框架 -->
<!-- tomcat-embed-* 内嵌Tomcat容器 -->
<!-- jackson 处理json数据 -->
<!-- spring-* Spring框架 -->
<!-- spring-boot-autoconfigure Spring Boot提供的自动配置功能 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<!--<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>-->
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
<build>
<finalName>springBoot</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
(三)配置文件、启动类:
项目路径如下:
application.yml配置文件中内容为:
#server
server:
# 项目contextPath,一般在正式发布版本中,我们不配置
context-path: /boot
# 该服务绑定IP地址,启动服务器时如本机不是该IP地址则抛出异常启动失败,只有特殊需求的情况下才配置
#address: 192.168.0.101
# 错误页,指定发生错误时,跳转的URL。请查看BasicErrorController源码便知
error:
path: /error
# 服务端口
port: 8080
# session最大超时时间(分钟),默认为30
session:
timeout: 60
tomcat:
# tomcat的URI编码
uri-encoding: utf-8
# tomcat最大线程数,默认为200
max-threads: 1000
# 存放Tomcat的日志、Dump等文件的临时文件夹,默认为系统的tmp文件夹(如:C:\Users\Shanhy\AppData\Local\Temp)
basedir: G:/springboot-tomcat-tmp
# 打开Tomcat的Access日志,并可以设置日志格式的方法:
#server.tomcat.access-log-enabled=true
#server.tomcat.access-log-pattern=
Application.java启动类如下,spring会扫描该类所在目录下的java类:
package com.sun; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* @Configuration:标注此文件为一个配置项
* @EnableAutoConfiguration:使用自动配置
* @ComponentScan:可扫描的
* @SpringBootApplication 包含上面三个
* Application:启动管理器
* Created by sun on 2017-1-14.
*/
@SpringBootApplication
public class Application implements CommandLineRunner { /* Servlet容器默认的Context路径是/
DispatherServlet匹配的路径(servlet-mapping中的url-patterns)是*//*
@ComponentScan路径被默认设置为SampleController的同名package,
也就是该package下的所有@Controller,@Service, @Component, @Repository都会被实例化后并加入Spring Context中。*/
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.run(args);
} // springboot运行后此方法首先被调用
// 实现CommandLineRunner抽象类中的run方法
@Override
public void run(String... args) throws Exception {
System.out.println("项目启动完成!");
}
}
TestController类:
package com.sun.test.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; /**
* 测试类
* Created by sun on 2017-1-14.
*/
@Controller
@RequestMapping("/test")
public class TestController { @RequestMapping("/")
@ResponseBody
String test(HttpServletRequest req){
return "Hello World!";
} }
启动Application,在页面上输入http://localhost:8080/boot/test/ 页面上打印出Hello World!
SpringBoot学习:IDEA中快速搭建springboot项目的更多相关文章
- springboot学习一:快速搭建springboot项目
1.idea创建springboot工程 JDK选择1.8以上的版本 选择springboot的版本和添加配置项 新建一个HelloController,测试 访问 http://localhost: ...
- 在线官网Spring Initializr 或 IntelliJ IDEA 快速搭建springboot项目
Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 那么,如何快速新建一个一个spring ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-2.快速搭建SpringBoot项目,采用IDEA
笔记 2.快速搭建SpringBoot项目,采用IDEA 简介:使用SpringBoot start在线生成项目基本框架并导入到IDEA中 参考资料: IDEA使用文档 ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-1.快速搭建SpringBoot项目,采用Eclipse
笔记 1.快速搭建SpringBoot项目,采用Eclipse 简介:使用SpringBoot start在线生成项目基本框架并导入到eclipse中 1.站点地址:http://start. ...
- 使用IDEA快速搭建Springboot项目
Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 下面就介绍一下如何使用idea快速搭建 ...
- 聊聊SpringBoot | 第一章:快速搭建SpringBoot第一个应用
快速搭建SpringBoot第一个应用 1.简介 本章仅介绍如何快速搭建第一个SpringBoot应用,细节内容下一章再做讲解,如果有需要,各位可以直接到Spring官网去了解. 从 Spring B ...
- 快速搭建springboot框架以及整合ssm+shiro+安装Rabbitmq和Erlang、Mysql下载与配置
1.快速搭建springboot框架(在idea中): file–>new project–>Spring Initializr–>next–>然后一直下一步. 然后复制一下代 ...
- 后续来啦:Winform/WPF中快速搭建日志面板
后续来啦:Winform/WPF中快速搭建日志面板 继昨天发文ASP.NET Core 可视化日志组件使用(阅读文章,查看视频)后,视频下有朋友留言 "Winform客户端的程序能用它不?& ...
- Spring Boot入门-快速搭建web项目
Spring Boot 概述: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...
随机推荐
- windows网络模型之完成端口(CompletionPort)详解 (转)
转载自:https://blog.csdn.net/piggyxp/article/details/6922277 目录: 1. 完成端口的优点 2. 完成端口程序的运行演示 3. 完成端口的相关概念 ...
- 论C/C++数据在内存中的二进制存放形式
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u010518429/article/details/30332237 // enter any ty ...
- 【HHHOJ】ZJOI2019模拟赛(十六)4.07 解题报告
点此进入比赛 得分: \(100+100+100=300\) 排名: \(Rank\ 1\) \(Rating\): \(+13\)(\(\frac18Rated\)) 备注: 这场比赛全是做过的原题 ...
- HDU 3613 扩展KMP
暴力枚举大水题,判断回文,扩展KMP #include <cstdio> #include <cstring> #include <algorithm> using ...
- 【luogu P1640 [SCOI2010]连续攻击游戏】 题解
题目链接:https://www.luogu.org/problemnew/show/P1640 数据有点水吧,从属性值连向对应武器编号. 枚举属性值匹配,遇到第一个无法匹配的直接跳出就好惹~. #i ...
- Android学习笔记_21_ViewFlipper使用详解 手势识别器
一.介绍ViewFilpper类 1.1 屏幕切换 屏幕切换指的是在同一个Activity内屏幕见的切换,最长见的情况就是在一个FrameLayout内有多个页面,比如一个系统设置页面:一个个性化设置 ...
- 122. Best Time to Buy and Sell Stock II ——LeetCode
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- TensorFlow安装环境的误区
安装py一定要注意安装的版本,我一开始安装的3.7版本的,现在还没有支持,另外,看清楚自己电脑是32位还是64位的
- Consul vs Zookeeper vs Etcd vs Eureka
为什么不应该使用ZooKeeper做服务发现 Eureka 更好 ,etcd作为一个受到Zookeeper与doozer启发而催生的项目,除了拥有与之类似的功能外,更具有以下4个特点{![引自Dock ...
- sqlServer2014安装说明(windows7 64位)
SqlServer2014安装说明(windows7 64位) 地址:https://www.microsoft.com/zh-cn/download/details.aspx?id=42299 1, ...