Spring Boot问题总结

news/2025/3/4 0:49:29/

1.程序包org.springframework.web.bind.annotation不存在

错误描述

执行install命令时报如下错误:

[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project springboot: Compilation failure: Compilation failure: 
[ERROR] /E:/Project/Eclipse/NINO/springboot/src/main/java/com/nino/springboot/SpringbootApplication.java:[5,47] 程序包org.springframework.web.bind.annotation不存在
[ERROR] /E:/Project/Eclipse/NINO/springboot/src/main/java/com/nino/springboot/SpringbootApplication.java:[6,47] 程序包org.springframework.web.bind.annotation不存在
[ERROR] /E:/Project/Eclipse/NINO/springboot/src/main/java/com/nino/springboot/SpringbootApplication.java:[9,2] 找不到符号
[ERROR]   符号: 类 RestController
[ERROR] /E:/Project/Eclipse/NINO/springboot/src/main/java/com/nino/springboot/SpringbootApplication.java:[12,10] 找不到符号
[ERROR]   符号:   类 RequestMapping
[ERROR]   位置: 类 com.nino.springboot.SpringbootApplication
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我的pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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"><modelVersion>4.0.0</modelVersion><groupId>com.nino</groupId><artifactId>springboot</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>springboot</name><description>Demo project for Spring Boot</description><!-- Spring Boot父级依赖,有了它就是个Spring Boot项目了 --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.6.RELEASE</version><relativePath /> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><!-- Spring Boot Maven插件,提供了很多方便的功能 --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
错误分析

参考了下其它正确的Spring Boot项目,发现是这行配置及代码出错了

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId>
</dependency>

把它改成如下代码,重新install成功了

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>

spring-boot-starter和spring-boot-starter-web的区别:

  • spring-boot-starter 是Spring Boot的核心启动器,包含了自动配置、日志和YAML
  • spring-boot-starter-web 支持全栈式Web开发,包括Tomcat和spring-webmvc

Web开发要用后者。

参考

Spring Boot的启动器Starter详解 - chszs的专栏 - CSDN博客
http://blog.csdn.net/chszs/article/details/50610474

2. Unable to start embedded container

问题描述
2015-12-22 09:30:23.582  INFO 3208 --- [           main] controller.UserController                : No active profile set, falling back to default profiles: default  
2015-12-22 09:30:23.879  INFO 3208 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12ceb70: startup date [Tue Dec 22 09:30:23 CST 2015]; root of context hierarchy  
2015-12-22 09:30:24.391  WARN 3208 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.  
2015-12-22 09:30:25.211 ERROR 3208 --- [           main] o.s.boot.SpringApplication               : Application startup failed  org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at controller.UserController.main(UserController.java:28) [classes/:na]  
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  ... 8 common frames omitted  
错误分析

猜测可能是代码编译问题,尝试重新编译,
于是执行Project–>Clean后无果
然后执行:右击项目–>Maven–>Update Project(Alt+F5)解决了。
貌似Maven项目重新编译时使用后者比较好使。

参考

Svn 的 Update 与Maven 的update project 作用有什么区别 - 费曼带我飞 - 博客园
http://www.cnblogs.com/xuyuanjia/p/5706411.html


http://www.ppmy.cn/news/1576415.html

相关文章

中间件专栏之Redis篇——Redis的三大持久化方式及其优劣势对比

Redis是内存数据库&#xff0c;它的数据一般存放在内存中&#xff0c;一旦断电或者宕机&#xff0c;存在内存中的数据就会丢失。当然&#xff0c;它也具备数据持久化的能力&#xff0c;本文就将介绍Redis的三种持久化方式及其优劣势对比。 一、RDB&#xff08;Redis Database&…

使用 C# 以api的形式调用 DeepSeek

一&#xff1a;创建 API 密钥 首先&#xff0c;您需要来自 DeepSeek 的 API 密钥。访问 DeepSeek&#xff0c;创建一个帐户&#xff0c;并生成一个新的 API 密钥。 二&#xff1a;安装所需的 NuGet 包 使用 NuGet 包管理器安装包&#xff0c;或在包管理器控制台中运行以下命…

每日一题——接雨水

接雨水问题详解 问题描述 给定一个非负整数数组 height&#xff0c;表示每个宽度为 1 的柱子的高度图。计算按此排列的柱子&#xff0c;下雨之后能接多少雨水。 示例 示例 1&#xff1a; 输入&#xff1a;height [0,1,0,2,1,0,1,3,2,1,2,1] 输出&#xff1a;6 解释&#…

【Linux】ubuntu server扩容硬盘

ubuntu server扩容硬盘 执行&#xff1a;lsblk lsblk # 看看硬盘设备输出如下&#xff1a; (base) difydify:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 73.9M 1 loop /snap/core22/1748 loop1 7:1 0 69.6M 1 loop /snap/go/10853 loop2 7:2 0 44.4M 1…

【音视频】图像基础概念

一、图像基础概念 1.1 像素 像素是一个图片的基本单位&#xff0c;pix使英语单词pixtureelement的结合“pixel”的简称&#xff0c;所以像素有图像元素之意。 例如2500*2000的照片就是指横向有2500个像素点&#xff0c;竖向有2000个像素点&#xff0c;总共500万个像素&#x…

波导阵列天线 学习笔记11双极化全金属垂直公共馈电平板波导槽阵列天线

摘要&#xff1a; 本communicaition提出了一种双极化全金属垂直公共馈电平板波导槽阵列天线。最初提出了一种公共馈电的单层槽平板波导来实现双极化阵列。此设计消除了传统背腔公共馈电的复杂腔体边缘的必要性&#xff0c;提供了一种更简单的天线结构。在2x2子阵列种发展了宽十…

Unity-DOTween插件

植物大战僵尸 - 阳光生成抛物线运动分析 下面是植物大战僵尸开发过程遇到的阳光以抛物线的形式生成的问题&#xff0c;查阅相关资料&#xff0c;下面是实现方法 代码实现 阳光的抛物线运动主要通过以下两个脚本实现&#xff1a; 1. SunFlower.cs - 向日葵生成阳光 public …

【JSON2WEB】15 银河麒麟操作系统下部署JSON2WEB

【JSON2WEB】系列目录 【JSON2WEB】01 WEB管理信息系统架构设计 【JSON2WEB】02 JSON2WEB初步UI设计 【JSON2WEB】03 go的模板包html/template的使用 【JSON2WEB】04 amis低代码前端框架介绍 【JSON2WEB】05 前端开发三件套 HTML CSS JavaScript 速成 【JSON2WEB】06 JSO…