Spring Boot踩坑之路一
Takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.
旨在简化创建产品级的 Spring应用和服务。Spring Boot 引导优先于配置,它可以让你避免繁杂的配置,尽可能的帮助你快速建站。
为什么使用Spring Boot
经过十多年的发展Spring家族已经壮大,要灵活使用Spring家族的产品已经变得有些困难,尤其是要维护一大堆的配置文件,在项目开发中令人头疼。Spring Boot解决了这个问题,并大大简化了我们的开发成本
其优点如下:
- 不用看一大坨的xml。用java config可以让你很容易明白一些框架的关键
- Spring Boot 要解决的问题, 精简配置是一方面, 另外一方面是如何方便的让spring生态圈和其他工具链整合(比如redis, email, elecsearch)
- 配合各种starter使用,基本上可以做到自动化配置
- 配合Maven或Gradle等构件工具打成Jar包后,Java -jar 简化部署运行
建立maven web项目
使用maven建立web项目,并参考官方文档进行版本选择和pom配置
POM中添加parent标签
添加parent后添加相关依赖不需要version
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
添加依赖
web工程的依赖,包括spring mvc tomcat等,spring boot会在需要时使用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
添加插件
用来在main方法中启动工程
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin </artifactId>
</plugin>
</plugins>
编写代码 HELLO WORLD
// 其中@SpringBootApplication申明让spring boot自动给程序进行必要的配置,等价于使用@Configuration,@EnableAutoConfiguration和@ComponentScan
@RestController
@SpringBootApplication
public class HelloWorld {
@RequestMapping("/")
public String hello() {
return "Hello World";
}
public static void main(String[] args) {
SpringApplication.run(HelloWorld.class,args);
}
}
检验成果
运行main函数之后访问http://localhost:8080/即可看到结果
我遇到的问题
问题出现在我建立maven项目编写java代码的时候在默认包中写的application类,并没有建立包。这种做法让Spring Boot每次都会扫描默认类及下属的所有类,浪费大量时间。所以在启动时会报警告,启动不成功
Your Application class should be placed in a specific package and not in the default (top-level) package. For example, put it in com.example and place all your application code in this package or in sub-packages like com.example.foo and com.example.bar.
Placing your Application class in the default package, i.e. directly in src/main/java isn't a good idea and it will almost certainly cause your application to fail to start. If you do so, you should see this warning:
** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
Spring Boot踩坑之路一的更多相关文章
- Spring Boot 踩坑之路之 Configuration Annotation Proessor not found in classpath
1. 出现spring boot Configuration Annotation Proessor not found in classpath的提示是在用了@ConfigurationProper ...
- spring boot踩坑记
Resolved exception caused by handler execution: org.springframework.http.converter.HttpMessageNotWri ...
- Spring WebSocket踩坑指南
Spring WebSocket踩坑指南 本次公司项目中需要在后台与安卓App间建立一个长连接,这里采用了Spring的WebSocket,协议为Stomp. 关于Stomp协议这里就不多介绍了,网上 ...
- html2canvas的踩坑之路
html2canvas的踩坑之路 前言 早有耳闻这个html2canvas比较坑,但无奈于产品需求的压迫,必须实现html转图片的功能,自此走上了填坑之路,好在最后的效果还算令人满意,这才没有误了产品 ...
- MySQL Connector/NET 使用小结(踩坑之路)
背景描述 根据项目的需要,需连接MySQL获取数据. 首先,先了解一下项目的情况: 之前的代码是C#编写的的, 运行时:.NETFramework3.5. 由于项目已经部署上线,因此不能升级运行时,这 ...
- Spring MVC 到 Spring Boot 的简化之路(山东数漫江湖)
背景 从Servlet技术到Spring和Spring MVC,开发Web应用变得越来越简捷.但是Spring和Spring MVC的众多配置有时却让人望而却步,相信有过Spring MVC开发经验的 ...
- Spring Boot的学习之路(02):和你一起阅读Spring Boot官网
官网是我们学习的第一手资料,我们不能忽视它.却往往因为是英文版的,我们选择了逃避它,打开了又关闭. 我们平常开发学习中,很少去官网上看.也许学完以后,我们连官网长什么样子,都不是很清楚.所以,我们在开 ...
- Android 上传开源项目到 jcenter 实战踩坑之路
本文微信公众号「AndroidTraveler」首发. 背景 其实 Android 上传开源项目到 jcenter 并不是一件新鲜事,网上也有很多文章. 包括我本人在将开源项目上传到 jcenter ...
- Spring MVC 到 Spring BOOT 的简化之路
背景 Spring vs Spring MVC vs Spring Boot Spring FrameWork Spring 还能解决什么问题 Spring MVC 为什么需要Spring Boot ...
随机推荐
- CSS——京东首页实战总结
第一天成果 1.浮动的盒子不要给宽,内容撑起盒子的宽 在前端设计中,一般不给浮动的盒子设置宽,让其用内容撑起一个高度. 2.小三角的表示 ◇用一个盒子(盒子宽为字的宽,高度为字高度的一半)去截取这个菱 ...
- java如何计算程序运行时间
long startTime = System.currentTimeMillis(); //获取开始时间 doSomething(); //测试的代码段 long endTime = S ...
- create schema 与create database的区别
概论第四版中增加了create schema (第三版好像没有这个内容),但是却没有提到create database.相反目前在大多数DBMS中(如SQL Server2000.Mysql等)都有 ...
- 一元线性回归分析及java实现
http://blog.csdn.net/hwwn2009/article/details/38414911 一元线性回归分析及java实现 2014-08-07 11:02 1072人阅读 评论(0 ...
- [Lua]Mac系统上安装Lua环境
1.下载 Lua语言的官方网站 http://www.lua.org/ 下载最新版本的Lua环境 2.安装 解压下载包lua-5.3.1.tar.gz 打开终端Terminal 使用cd命令进入该目录 ...
- [Unity AssetBundle]Asset资源处理
什么是AssetBundle 在很多类型游戏的制作过程中,开发者都会考虑一个非常重要的问题,即如何在游戏运行过程中对资源进行动态的下载和加载.因此,Unity引擎引入了AssetBundle这一技术来 ...
- 安装php扩展后,执行时找不到扩展 class xxx no found
当编译安装一个新的php扩展,例如安装redis, 安装后 执行 new Redis(), 如果发现找不到class Redis,可以先检查redis.so文件是否在php的扩展目录下, 如果发现是, ...
- JNI介绍(转)
源:JNI介绍 JNI是在学习Android HAL时必须要面临一个知识点,如果你不了解它的机制,不了解它的使用方式,你会被本地代码绕的晕头转向,JNI作为一个中间语言的翻译官在运行Java代码的An ...
- 制作毛玻璃效果 分类: ios技术 2015-07-14 09:03 240人阅读 评论(0) 收藏
//添加一个图片 UIImageView *imageview = [[UIImageView alloc]init]; imageview.frame = CGRectMake(10 ...
- nodejs抓取数据二(列表解析)
这里做得比较暴力,没有分页取出数据解析,O(∩_∩)O哈哈~,居然没有被挂机.不过解析的坑特别多...不过大部分我想要的数据都拿到了. //解析列表数据 var http = require(&quo ...