Spring Boot Starter:2.1.4。发行
我正在尝试使用spring-cloud-starter-netflix-zuul在春季启动时设置服务代理,但是jar在启动过程中引发了以下异常
***************************
APPLICATION FAILED TO START
***************************
Description:
Field server in org.springframework.cloud.netflix.zuul.ZuulServerAutoConfiguration required a bean of type 'org.springframework.boot.autoconfigure.web.ServerProperties' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=false)
Action:
Consider defining a bean of type 'org.springframework.boot.autoconfigure.web.ServerProperties' in your configuration.
下面是我的主要
package com.xxx.serviceproxy;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
@Configuration
@ComponentScan
@EnableAutoConfiguration
@Controller
@EnableZuulProxy
@SpringBootApplication
public class ServiceProxyApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ServiceProxyApplication.class).web(WebApplicationType.NONE).run(args);
}
}
答案 0 :(得分:1)
之所以会发生这种情况,是因为您要添加注释 @EnableAutoConfiguration 。
此注释导致搜索类 ZuulServerAutoConfiguration 。
您可以在这里看到:
具有从
自动连线的@Autowired
protected ServerProperties server;
在类的标题中,您可以看到注释:
// Make sure to get the ServerProperties from the same place as a normal web app would
// FIXME @Import(ServerPropertiesAutoConfiguration.class)
public class ZuulServerAutoConfiguration {
这意味着它没有自动配置。
如果删除注释 @EnableAutoConfiguration ,它将不再寻找zuul自动配置,并且可以在application.yml(或application.properties)中配置zuul路径和其他功能,例如:< / p>
zuul:
routes:
users:
path: /myusers/**
serviceId: users_service
这里是配置zuul的文档:
https://cloud.spring.io/spring-cloud-netflix/multi/multi__router_and_filter_zuul.html