Reputation: 2019
Spring Boot Starter : 2.1.4.RELEASE
i am trying to use spring-cloud-starter-netflix-zuul to setup service proxy in spring boot, however the jar throws the below exception during startup
***************************
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.
Below is my Main
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);
}
}
Upvotes: 0
Views: 4108
Reputation: 2235
This happens because you are putting the annotation @EnableAutoConfiguration.
This annotation causes the class ZuulServerAutoConfiguration to be searched for.
You can see here:
which has an autowired from
@Autowired
protected ServerProperties server;
And in the header of the class you can see the comments:
// Make sure to get the ServerProperties from the same place as a normal web app would
// FIXME @Import(ServerPropertiesAutoConfiguration.class)
public class ZuulServerAutoConfiguration {
which means it's not auto-configuring.
If you remove the annotation @EnableAutoConfiguration, it will no longer look for zuul autoconfiguration and you can configure zuul paths and other features in your application.yml (or application.properties), example:
zuul:
routes:
users:
path: /myusers/**
serviceId: users_service
Here the documentation to configure zuul:
https://cloud.spring.io/spring-cloud-netflix/multi/multi__router_and_filter_zuul.html
Upvotes: 1