1、注册“gulimall-gateway”到Nacos
1)创建“gulimall-gateway”
SpringCloud gateway
2)添加“gulimall-common”依赖和“spring-cloud-starter-gateway”依赖
<dependency> <groupId>com.bigdata.gulimall</groupId> <artifactId>gulimall-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency>
3)“com.bigdata.gulimall.gulimallgateway.GulimallGatewayApplication”类上加上“@EnableDiscoveryClient”注解
4)在Nacos中创建“gateway”命名空间,同时在该命名空间中创建“gulimall-gateway.yml”
5)创建“bootstrap.properties”文件,添加如下配置,指明配置中心地址和所属命名空间
spring.application.name=gulimall-gateway spring.cloud.nacos.config.server-addr=192.168.137.14:8848 spring.cloud.nacos.config.namespace=1c82552e-1af0-4ced-9a48-26f19c2d315f
6)创建“application.properties”文件,指定服务名和注册中心地址
spring.application.name=gulimall-gateway spring.cloud.nacos.discovery.server-addr=192.168.137.14:8848 server.port=88
7)启动“gulimall-gateway”
启动报错:
Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class
解决方法:在“com.bigdata.gulimall.gulimallgateway.GulimallGatewayApplication”中排除和数据源相关的配置
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
重新启动
访问:http://192.168.137.14:8848/nacos/#,查看到该服务已经注册到了Nacos中