Spring Boot Starter: 2.1.4.RELEASE
Я пытаюсь использовать 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); } }
Это происходит потому, что вы помещаете аннотацию @EnableAutoConfiguration.
Эта аннотация вызывает поиск класса ZuulServerAutoConfiguration .
Выможно посмотреть здесь:
https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/ZuulServerAutoConfiguration.java
, который имеет автопроводку от
@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, и вы сможете настроить пути zuul и другие функциив вашем application.yml (или application.properties), например:
zuul: routes: users: path: /myusers/** serviceId: users_service
Вот документация для настройки zuul:
https://cloud.spring.io/spring-cloud-netflix/multi/multi__router_and_filter_zuul.html