spring-boot - 无法启动 ServletWebServerApplicationContext
问题描述
我正在通过阅读官方网站上的教程来学习spring-boot http://spring.io
。当我尝试实现一个服务发现客户端时,我得到了这个错误信息:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
. 我在 Google 上阅读了很多解决方案,但没有一个有帮助。你能给我一些建议吗?我是弹簧靴的新手。这是我的代码:
- spring-boot 应用程序类
@EnableDiscoveryClient
@SpringBootApplication
public class DiscoveryClientApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DiscoveryClient.class, args);
}
}
- 控制器类:
@RestController
public class Controller {
@Autowired
private DiscoveryClient discoveryClient;
@RequestMapping("service-instances/{appName}")
public List<ServiceInstance> serviceInstanceByApplicationName(@PathVariable
String applicationName) {
return this.discoveryClient.getInstances(applicationName);
}
}
- 和 application.properties
server.port = 20000
eureka.instance.prefer-ip-address = true
eureka.client.register-with-eureka = true
eureka.client.fetch-registry = true
eureka.client.service-url.default-zone = http://localhost:8761/eureka
spring.application.name = service-discovery-client
spring.jpa.hibernate.ddl-auto = create
spring.datasource-url = jdbc:mysql://localhost:3306/spring-test
spring.datasource.username = root
spring.datasource.password = 80966cc9
spring.jpa.database = MYSQL
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
我的项目是一个maven项目,发现客户端是一个子项目,它的pom.xml继承自父项目。在父项目中,我添加了所有依赖项。另外两个子项目运行正常,只有这个服务不能运行。
解决方案
推荐阅读
- ios - 将 json 数据显示为部分取决于表视图中发布的年份
- java - 在 IntelliJ 中使用 Maven 和 Spring 和 Apache Spark 会导致错误
- objective-c - 如何将objective-c语言(`va_list`,`va_start`,`va_end`)转成swift语言?
- email - 使用 [Python 3.6] 提取电子邮件正文
- python - 具有不同形状的pyplot绘图
- android - 如果我只知道firebase中的UID,我可以登录用户帐户吗
- ios - 如何创建像 iOS 共享表菜单这样的短模态叠加层?
- java - OneToOne 关系,只保留外键
- java - 用户使用 Apache Shiro 和 JSP 重新登录时如何重定向到主页
- c# - 向类传递值不断返回 0