spring boot. 1 学习,配置404 错误.

本文记录了作者第一天学习Spring Boot的过程,包括按照官方文档搭建RESTful Web Service项目,使用Maven、IntelliJ IDEA及JDK 1.9进行配置。文章详细描述了在启动过程中遇到的问题及解决方法,如解决因Bean缺失导致的嵌入式容器无法启动的问题,以及如何正确配置扫描路径来避免404错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一天学习spring .

1.按照官方文档搭项目.

https://spring.io/guides/gs/rest-service/#initial   

Building a RESTful Web Service

2.搭建项目. maven  idea   jdk 1.9

选中的maven -web -app/  但是看这选择  manve-quickstart 应该也是可以的.


创建完成之后 runas 出现两个问题.

 1无法启动,

.Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

 一般都是说tomcat引用冲突的问题.不过我没有用啊.所以就看源码:


   发现beanNames 为0 ,查看了原来的的代码 启动类.因为是复制的

 

   复制代码用的Application 结果一来的包有这个类就给引入进去了,半天起不起来.用创建的启动类的类对象 xxx.class

2.启动之后是 404 

首先这个项目不需要在路径上写项目名.


http://localhost:8080/greeting
访问不到.查看加载的mapped 日志 发现{"greeting"}没有加载.

后面查询发现, spring boot 的启动类扫描的是当前包以及子包. 如果要加包的扫描路径才可以.


解决了 .可以访问.



? 内嵌的tomcat 如果工作,.

[ERROR] Errors: [ERROR] ApiServiceTest.testCallConsentServiceVerifyConsent_thenReturnBadRequest » IllegalState Failed to load ApplicationContext for [WebMergedContextConfiguration@2dfeb141 testClass = unit.ApiSer viceTest, locations = [], classes = [com.dahsing.api.Application], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframewo rk.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper=true"], contextCustomizers = [[ImportsContextCustomizer@629e8212 key = [org.springframework.boot.autoconfigure.task.TaskExecution AutoConfiguration, org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration, org.springframework.boot.aut oconfigure.validation.ValidationAutoConfiguration, org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration, org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfigu ration, org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration, org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration, org.springframework.boot.test.autocon figure.web.reactive.WebTestClientAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMv cAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration, org.sp ringframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration, org.springframework .boot.test.autoconfigure.web.servlet.MockMvcSecurityConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebClientAutoConfiguration, org.springframework.boot.test.autoconfig ure.web.servlet.MockMvcWebDriverAutoConfiguration, org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration, org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration, org .springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration, org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.We bMvcAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2Reso urceServerAutoConfiguration, org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration, org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration]], org. springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@28b46423, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@ 48c76607, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$ DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@3fc79729, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurati onContextCustomizer@1187c9e8, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.bo ot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@35ae581d, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@14deeb89, org.springframework.boot. test.autoconfigure.web.servlet.WebDriverContextCustomizer@9573584, org.springframework.test.context.web.socket.MockServerContainerContextCustomizer@53251a66, org.springframework.boot.test.context.SpringBootTestAnnotation@bcb91adb], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null] [INFO] [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
最新发布
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值