• SpringBoot2.x 依赖环境和版本新特性说明

    依赖版本 jdk8 以上, Springboot2.x 用 JDK8 , 因为底层是 Spring framework5 。

  • jar 包方式运行 SpringBoot 项目时问题

    打包成jar包,需要增加maven依赖。

    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    </plugins>
    </build>

    如果没加相关依赖,执行 maven 打包,运行后会报错: no main manifest attribute, in XXX.jar。

    原因解释:

    将 jar 文件文件后缀改为 zip 解压后得到目录如下:

    		example.jar
    |
    +-META-INF
    | +-MANIFEST.MF
    +-org
    | +-springframework
    | +-boot
    | +-loader
    | +-<spring boot loader classes>
    +-BOOT-INF
    +-classes
    | +-mycompany
    | +-project
    | +-YourClasses.class
    +-lib
    +-dependency1.jar
    +-dependency2.jar

    当没有引用 maven 插件的时候,就没有生成的 MANIFEST.MF 文件,而在 MANIFEST.MF 中有 Main-Class: org.springframework.boot.loader.JarLauncher,这会启动类加载器,类加载器会加载应用的主要函数,即执行 Start-Class: com.rookie.BaseProjectApplication,这就是程序入口。运行后会报错:no main manifest attribute, in XXX.jar,就是找不到 MANIFEST.MF 的

    Start-Class: xx.xx.xxApplication。入口函数都找不到,你说如何启动加载呢?肯定会加载失败的。

  • @RestController 和 @RequestMapping 注解不生效

    引入 Web 模块,需在 pom.xml 添加 spring-boot-starter-web 模块

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  • SpringBoot 启动失败信息如下:
    ***************************
    APPLICATION FAILED TO START
    ***************************
    Description:
    Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
    Reason: Failed to determine a suitable driver class
    Action:
    Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
    Process finished with exit code 1

    原因是:创建 Spring Boot 项目时,在选择组件时添加了 mysql、mybatis 组件,添加了数据库组件,所以 autoconfig 会去读取数据源配置,而新建的项目还没有配置数据源,所以会导致异常出现。

    解决方案:

    ①:需要在启动类的 @EnableAutoConfiguration 或 @SpringBootApplication 中添加

    exclude = {DataSourceAutoConfiguration.class},排除此类的autoconfig。

    ②:添加数据库配置信息

    spring.datasource.jdbc-url=jdbc:mysql://localhost:3316/test1
    spring.datasource.username=root
    spring.datasource.password=root
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  • service 注入失败、@Autowired 注入失败 参考以下链接

    https://my.oschina.net/hxflar1314520/blog/1800035

Spring Boot 2.0 常见问题总结(一)的更多相关文章

  1. Spring Boot 2.0 常见问题总结(二)

    使用 IDEA 生成 POJO 实体类 a. 使用 idea 连接上需要操作的数据库. b. 选中要生成实体类的数据库表:右键 ---> Scripted Extensions ---> ...

  2. springboot2.0(一):【重磅】Spring Boot 2.0权威发布

    就在昨天Spring Boot2.0.0.RELEASE正式发布,今天早上在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误, ...

  3. 业余草分享 Spring Boot 2.0 正式发布的新特性

    就在昨天Spring Boot2.0.0.RELEASE正式发布,今天早上在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误, ...

  4. Spring Boot 2.0(二):Spring Boot 2.0尝鲜-动态 Banner

    Spring Boot 2.0 提供了很多新特性,其中就有一个小彩蛋:动态 Banner,今天我们就先拿这个来尝尝鲜. 配置依赖 使用 Spring Boot 2.0 首先需要将项目依赖包替换为刚刚发 ...

  5. Spring Boot 2.0(四):使用 Docker 部署 Spring Boot

    Docker 技术发展为微服务落地提供了更加便利的环境,使用 Docker 部署 Spring Boot 其实非常简单,这篇文章我们就来简单学习下. 首先构建一个简单的 Spring Boot 项目, ...

  6. spring boot 2.0.0由于版本不匹配导致的NoSuchMethodError问题解析

    spring boot升级到2.0.0以后,项目突然报出 NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBu ...

  7. Spring Boot 2.0(六):使用 Docker 部署 Spring Boot 开源软件云收藏

    云收藏项目已经开源2年多了,作为当初刚开始学习 Spring Boot 的练手项目,使用了很多当时很新的技术,现在看来其实很多新技术是没有必要使用的,但做为学习案例来讲确实是一个绝佳的 Spring ...

  8. Spring Boot 2.0系列文章(五):Spring Boot 2.0 项目源码结构预览

    关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/15/springboot2_code/ 项目结构 结构分析: Spring-boot-pr ...

  9. Spring Boot 2.0系列文章(七):SpringApplication 深入探索

    关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/30/springboot_SpringApplication/ 前言 在 Spring B ...

随机推荐

  1. java while循环

    /* while 循环有一个标准格式,还有一个扩展格式 标准格式: while(条件表达式){ 循环体 } 扩展格式: 初始化语句; while(条件判断){ 循环体 步进表达式 } */ publi ...

  2. 力扣—climbing stairs(爬楼梯) python实现

    题目描述: 中文: 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 英文: You are cl ...

  3. 所有anaconda安装包失败的解决办法汇总

    多试几次,有时候网络不稳定下载一半会停掉 更改Pip源 pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple 1.首先确认镜像源 ...

  4. css雪碧图实现数字切换

    vue中 css 雪碧图应用及数字切换demo 1. CSS Sprites一般只能使用到固定大小的盒子(box)里,这样才能够遮挡住不应该看到的部分. 2.使用css雪碧图的优点: 利用CSS Sp ...

  5. ajax中json格式数据如何朝后端发送数据

  6. String StringBuffer BufferBuilder区别

    String 是一个字符串常量,即该对象一旦被创建之后是不可以进行更改的 StringBuffer StringBuilder 是一个字符串变量 StringBuffer 是非线程安全的 但是Stri ...

  7. horizontalAccuracy 检测定位成功

    - (void)findCurrentLocation { self.isFirstUpdate = YES; [self.locationManager startUpdatingLocation] ...

  8. Oracle数据库中,sql中(+)(-)的含义

    SELECT *FROM TABLE1 A,TABLE2 B WHERE A.ID(+)=B.ID; 右连接=RIGHT JOIN SELECT *FROM TABLE1 A,TABLE2 B WHE ...

  9. 前端每日实战:80# 视频演示如何用纯 CSS 创作一个自行车车轮

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/XBXEPK 可交互视频 此视频是可 ...

  10. C语言编译exe添加图标

    C语言是一门通用的计算机编程语言,可以直接编译为可执行文件.在windows下,可执行文件的后缀是exe,我们编写一个最简单的程序test.c: #include <stdlib.h> i ...