首页 > 解决方案 > 无法启动 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);
    }

}

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继承自父项目。在父项目中,我添加了所有依赖项。另外两个子项目运行正常,只有这个服务不能运行。

标签: spring-bootnetflix-eureka

解决方案


推荐阅读