Spring Boot问题总结

server/2025/2/28 23:29:31/

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/server/171412.html

相关文章

Vue3状态管理新选择:Pinia使用完全指南

一、为什么需要状态管理&#xff1f; 在Vue应用开发中&#xff0c;当我们的组件树变得复杂时&#xff0c;组件间的数据传递会成为棘手的问题。传统方案&#xff08;如props/$emit&#xff09;在多层嵌套组件中会变得笨拙&#xff0c;这时状态管理工具应运而生。Vue3带来了全新…

AI开发利器:Anaconda

在Python开发过程中&#xff0c;不同的项目可能会依赖不同版本的Python以及各种不同版本的库。比如&#xff0c;项目A可能依赖Python 3.8和某个特定版本的numpy、TensorFlow和PyTorch&#xff0c;而项目B可能需要Python 3.9以及另一个版本的numpy库。如果直接在系统中安装Pytho…

java23种设计模式-单例模式

单例模式&#xff08;Singleton Pattern&#xff09;学习笔记 &#x1f31f; 定义 单例模式属于创建型设计模式&#xff0c;确保一个类只有一个实例&#xff0c;并提供全局访问点。是Java中最简单但实现最复杂的设计模式。 &#x1f3af; 适用场景 需要控制资源访问&#xf…

SDN架构详解

目录 1&#xff09;经典的IP网络-分布式网络 2&#xff09;经典网络面临的问题 3&#xff09;SDN起源 4&#xff09;OpenFlow基本概念 5&#xff09;Flow Table简介 6&#xff09;SDN的网络架构 7&#xff09;华为SDN网络架构 8&#xff09;传统网络 vs SDN 9&#xf…

蓝桥杯之日期题

文章目录 1.蓝桥杯必备知识点2. 题型13.需求2 1.蓝桥杯必备知识点 蓝桥杯是一个面向全国高校计算机相关专业学生的学科竞赛&#xff0c;涵盖多个赛道&#xff0c;常见的有软件类&#xff08;如 C/C 程序设计、Java 软件开发、Python 程序设计&#xff09;和电子类&#xff08;…

Spring Core面试题

Spring Core面试题 基础概念 Q1: Spring的核心特性有哪些&#xff1f; public class SpringCoreBasicDemo {// 1. IoC容器public class IoCExample {public void iocDemo() {// XML配置Configurationpublic class AppConfig {Beanpublic UserService userService() {return …

Nmap使用指南

Nmap使用指南 Nmap (网络映射器) 是一款强大的应用网络扫描和安全核查工具&#xff0c;适合于网络管理和安全专家。本文将介绍Nmap的基本使用方法&#xff0c;包括基本命令和常用功能。 1. 基本使用方式 Nmap的基本命令格式如下&#xff1a; nmap [选项] 目标地址目标地址 可…

火狐浏览器多开指南:独立窗口独立IP教程

无论是跨境电商从业者需要管理多个店铺账号&#xff0c;还是海外社交媒体营销人员要运营多个社交平台账号&#xff0c;亦或是从事多账号广告投放的人员&#xff0c;都面临着一个共同的挑战 —— 如何高效管理多个账号&#xff0c;并确保每个账号的独立性。 在这种情况下&#…