您现在的位置是:首页 >技术交流 >springcloud 新建微服务,注册到Eureka服务器的过程总结网站首页技术交流

springcloud 新建微服务,注册到Eureka服务器的过程总结

香至 2024-07-12 06:01:02
简介springcloud 新建微服务,注册到Eureka服务器的过程总结

springcloud  新建微服务,注册到Eureka服务器的过程总结:

1、引入依赖:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

2、配置文件:

#u5e94u7528(u670du52a1)u540du79f0
spring.application.name=user-service
server.port=8301

#eurekau914du7f6e
#spring.boot.admin.client.url=http://localhost:8600
management.security.enabled=false
management.endpoints.web.exposure.include=*
management.endpoints.health.show-details=ALWAYS
management.endpoint.heapdump.enabled=false
management.endpoint.threaddump.enabled=false
management.health.db.enabled=false
management.endpoint.shutdown.enabled=true

eureka.instance.leaseRenewalIntervalInSeconds=5
eureka.instance.lease-expiration-duration-in-seconds=5
eureka.instance.prefer-ip-address=true
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

eureka.client.registryFetchIntervalSeconds=5

ribbon.ServerListRefreshInterval=5000

ribbon.ConnectTimeout=2000
ribbon.ReadTimeout=2000
ribbon.MaxAutoRetriesNextServer=1
ribbon.MaxAutoRetries=1
ribbon.OkToRetryOnAllOperations=true

#config center
spring.cloud.config.label=master
spring.cloud.config.profile=dev
spring.cloud.config.uri=http://localhost:9000/

3、使用@EnableEurekaClient开启服务:

@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication()
public class UserClientApplication {
    static Logger logger = LoggerFactory.getLogger(UserClientApplication.class);

    private static final String CUSTOM_COUNTER = "xxl_my_counter";

    public static void main(String[] args) {
        try {
            ConfigurableApplicationContext run = new SpringApplicationBuilder(UserClientApplication.class).web(true).run(args);

        } catch (Exception e) {
            logger.error("", e);
        }
    }

    @Configuration
    public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().permitAll()
                    .and().csrf().disable();
        }
    }
}
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。