创建springboot工程
1.New Project -> Spring Initializr
2.Next -> Spring Boot版本选择3.x -> 勾选Spring Web
3.编写Cotroller
4.启动Spring Boot并在浏览器地址栏中输入 localhost:8080/hello查看效果
手动创建springboot工程
1.创建maven工程
file -> Project Structure -> 上边➕ -> new module -> 选择版本号,命名
2.引入依赖 project(一级)标签里
3.提供启动类并新建resources文件夹下application.properties
启动类名字最好与项目名称一致,后面跟着Application
maven环境配置
maven的环境配置问题:出现无法解析插件_maven无法解析插件-CSDN博客
Spring Validation参数校验
JWT令牌
跟敲过程出现的问题:
一、Cannot resolve plugin org.apache.maven.plugins:maven-compiler-plugin:3.1
这个错误表明Maven在构建项目时无法解析或下载指定的插件org.apache.maven.plugins:maven-compiler-plugin:3.1
。Maven在其本地仓库和远程仓库中查找插件,如果找不到,它会报这个错误。
解决方法:
-
检查网络连接:确保你的计算机可以连接到Maven中央仓库。
-
检查Maven配置:确认
settings.xml
文件中的仓库配置正确,没有导致连接问题。 -
清理本地仓库:有时候本地仓库中的插件可能损坏,尝试运行
mvn clean
命令清理项目,然后再次构建。 -
检查
pom.xml
:确保<pluginRepositories>
配置正确,如果需要的话,可以添加Maven中央仓库或其他公共仓库的地址。 -
手动安装插件:如果上述方法都不行,可以尝试从其他来源手动下载
maven-compiler-plugin
的3.1版本,并使用mvn install:install-file
命令安装到本地仓库。
如果你的项目确实需要这个特定版本的插件,而且上述方法都无法解决问题,可能需要考虑是否有其他网络或权限问题导致无法获取。如果项目可以不使用这个特定版本,可以尝试更新pom.xml
中的插件版本号到一个可用的版本。
由于我使用的idea是2021版本,不是2022以上,所以不采用new project方式,而是采用new module
二、Could not find artifact org.springframework.boot:spring-boot-stater-web:pom:unknown in alimaven
报错解释:
这个错误表明Maven构建工具在尝试构建一个Spring Boot项目时,无法找到指定的依赖项spring-boot-stater-web
。这个依赖项的groupId应该是org.springframework.boot
,但是在这个依赖项的名字中存在一个错误,正确的名字应该是spring-boot-starter-web
,而不是spring-boot-stater-web
(少了一个'r'字母)。
解决方法:
-
检查你的项目中的
pom.xml
文件,找到包含错误依赖的地方。 -
更正依赖项的名字,将
spring-boot-stater-web
改为spring-boot-starter-web
。 -
保存
pom.xml
文件。 -
运行Maven命令(例如
mvn clean install
)来重新构建项目。
确保你的Maven仓库设置正确,并且你有权访问Maven中央仓库或者任何配置的私有仓库。如果问题依然存在,可能需要检查网络连接或者仓库的配置。
三、Terminated with exit code 1
IDEA报错Terminated with exit code 1最新解决方案-CSDN博客
四、springboot启动失败
初始化项目的时候已经定义一个helloController的方法,basicController中的删除
五、Unresolved plugin: 'org.apache.maven.plugins:maven-clean-plugin:3.2.0'
从以下官网上搜索对应的包下载
六、org.springframework.core.io.support.SpringFactoriesLoader.forDefaultResourceLocation(java.lang.ClassLoader)'
依赖的版本不适配
七、
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
数据库配置问题,yml文件放在resources目录下,我却放在其子目录下了。
八、Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.mybatis.spring.MyBatisSystemException] with root cause
接口调试的响应码为500
解决方法:在controller层中的方法参数前加入@RequestBody注解,之后响应码变为400,但是数据没有写回
请求参数格式选成了form-data,出现以上情况,改成urlencoded格式,出现Data too long for column 'username' at row 1并且响应码又变成500,将@RequestBody注解删掉,成功解决。
九、
JSON parse error: Cannot construct instance of `com.pet.pojo.User` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)",
cannot deserialize from Object value (no delegate- or property-based Creator) 解决方法-CSDN博客
十、Cannot invoke "com.pet.mapper.PetMapper.add(com.pet.pojo.Pet)" because "this.petMapper" is null
添加@Autowired
十一、Could not autowire. No beans of 'StringRedisTemplate' type found.