初学spring boot踩过的坑
一、搭建spring boot环境
maven工程
pom文件内容
|
<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/xsd/maven-4.0.0.xsd"> <parent> |
项目目录结构

其中springTest类是spring boot内部tomcat启动时要运行的类
其中内容如下
| package com.qm;
import org.springframework.boot.SpringApplication; import com.qm.controller.UserController; @SpringBootApplication |
Application类的作用是外部服务器启动spring boot所要做的一些事。内容如下
|
package com.qm; import org.springframework.boot.SpringApplication; @SpringBootApplication |
application.properties文件内容如下
|
server.port=8080 //热部署,需要提供的路径 |
踩过的坑
坑一,
一开始以为文件目录,可以随便放,经过坑一的教训,才知道代码文件存放有一定的顺序
如上项目结构图,其中springtest类和application类一定要放在最外面的包里,如com.qm 当启动spring boot时,它会去加载com.qm包及其子包下的所有类,
当你不按顺序时,且代码中有@Autowired注解注入bean时,会报以下错误
Description:
Field userService in com.qm.controller.UserController required a bean of type 'com.qm.service.UserService' that could not be found.
Action:
Consider defining a bean of type 'com.qm.service.UserService' in your configuration.
,即bean找不到。,这是应该注意代码顺序。
坑二
补齐坑一后,在service层的接口继承jpa,然后在controller层使用注入的service方法会报以下错误
Error creating bean with name 'dataController': Unsatisfied dependency expressed through field 'personRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property auto found for type Person!
这是因为hibernate版本的问题,
只要加上
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.1</version>
这个依赖即可
添加之后,若maven仓库中有该jar包,最好删掉,编译时重新下载
若spring boot正常启动,而地址栏访问不到controller,则此时应该注意,spring boot启动时,未扫描到controller类,
在spring boot入口类上再添加一个注解
@ComponentScan("要扫描的包名")
以上就是我在学spring boot时遇到过得一些坑。
初学spring boot踩过的坑的更多相关文章
- 部署spring boot + Vue遇到的坑(权限、刷新404、跨域、内存)
部署spring boot + Vue遇到的坑(权限.刷新404.跨域.内存) 项目背景是采用前后端分离,前端使用vue,后端使用springboot. 工具 工欲善其事必先利其器,我们先找一个操作L ...
- Spring Boot踩坑之路一
Takes an opinionated view of building production-ready Spring applications. Spring Boot favors conve ...
- 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 boot 报错 Whitelabel Error Page 404
按照教程,写了个最简单的 HelloWorld,尼玛报错 -->Whitelabel Error Page 404. 网上99%都是项目结构不对,说什么 Application放在父级 pack ...
- 记录初学Spring boot中使用GraphQL编写API的几种方式
Spring boot+graphql 一.使用graphql-java-tools方式 <dependency> <groupId>com.graphql-java-kick ...
- spring boot 枚举使用的坑3
上一篇说到spring boot 使用jackson在枚举enum序列化和反序列化的问题, 再来说说在JPA中实体entity使用枚举的问题. 还是这个枚举: @Getter @AllArgsCons ...
- spring boot 枚举使用的坑
java 枚举的功能挺多,但是坑更多,使用的时候要注意.如下面这个枚举. @Getter @AllArgsConstructor public enum EnumExpenseType impleme ...
- Spring Boot 学习填的坑一
1.关于springBoot自动扫描规则: SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描! "Application"类是指 ...
随机推荐
- 2-LPC1778之GPIO
其实这篇文章主要是介绍自己为其写的GPIO库,自己借鉴了原子写的STM32,野火写的K60,还有LPC官方库,然后按照自己平时用的,然后写了一个..其实写库的主要目的是为了方便(主要是方便操作)以后自 ...
- EntityFramework6.X 之LocalDB&ConnectionString
LocalDB 面向开发人员的SQL Server Express的执行模式,它的安装将复制启动SQL Server数据库引擎所需的最少文件集且使用特定连接字符串来启动连接,它是可以创建和打开SQL ...
- 2016 UESTC Training for Dynamic Programming
强行做做试试看吧. http://acm.hust.edu.cn/vjudge/contest/124721#overview 密码:mytrain C - 柱爷与咸鱼神功 一个简单01背包. #in ...
- /proc/kcore失效,调试其文件系统相关模块,使重新正常工作
为分析内核,在有限的机器上用虚拟机装了CentOS.6.9.i386.minimal,重新编译了3.19.8内核并克隆.当使用/proc/kcore进行内核动态映像调试时,发现与kgdb远程调试端读到 ...
- redis入门指南-第7章-管理
7.1 持久化 1.RDB方式 2.AOF方式 Redis 持久化: 提供了多种不同级别的持久化方式:一种是RDB,另一种是AOF. RDB 持久化可以在指定的时间间隔内生成数据集的时间点快照(poi ...
- php-fpm 与 fastCgi的浅谈
首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者. web server(比如说nginx)只是内容的分发者.比如,如果请求/index.h ...
- grunt基础配置
grunt基础配置 要使用grunt来管理项目,一般需要如下的几个步骤: 安装grunt命令行工具grunt-cli 在项目中安装grunt 安装grunt插件 建立并配置Gruntfile.js 安 ...
- 传统平面广告已OUT出局,VR全景异军突起——VR全景智慧城市
VR,近两年异军突起的"黑科技".从1935年斯坦利·温鲍姆首次在小说中描述VR眼镜,到如今PC头盔.VR分体机以及VR一体机的相继问世,VR自身已从虚拟走向现实.而当硬件迭代逐步 ...
- Javaweb---如何使用eclipse创建Javaweb项目
在配置好--服务器Tomcat与Eclipse后,进行项目创建 配置地址:http://blog.csdn.net/baidu_37107022/article/details/71405194 流程 ...
- 一天搞定CSS:字体font--04
1.字体体系 2.字体各属性取值 说明: 每一个属性后面的分支是属性值,以及对属性值的说明. 比如font-weight- - - -有两个取值:bold,normal 3.演示代码 <!DOC ...