本示例说明本地如何进行开发一个服务。
git clone https://gitlab.tcsoft.info:8988/tcc-open-source/ofa-example.git
此项目是为了说明服务应有的项目结构和相关的配置说明,实际开发可参考此项目进行调整,不可在此项目上直接开发。
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.com.tcc.ofa"})
@ComponentScan(basePackages = {"cn.com.tcc.ofa"})
@MapperScan("cn.com.tcc.ofa.*.mapper")
@EnableTransactionManagement
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
添加maven私服地址,同时引入ofa-common包
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ofa-dependencies</artifactId>
<groupId>cn.com.tcc.ofa</groupId>
<version>1.0.3-SNAPSHOT</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>cn.com.tcc.ofa</groupId>
<artifactId>ofa-example</artifactId>
<version>${parent.version}</version>
<dependencies>
<dependency>
<groupId>cn.com.tcc.ofa</groupId>
<artifactId>ofa-common</artifactId>
<version>${parent.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>tcc-maven-public</id>
<name>tcc-maven-public</name>
<url>http://j.tcsoft.info:58080/nexus/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
spring.cloud.nacos.discovery.server-addr
配置为本地的nacos注册中心地址
spring.cloud.nacos.config.server-addr
为配置中心地址。
spring.application.name
为具体的服务名称,可根据实际业务去命名,网关即通过此名字寻找对应的服务。
spring:
application:
name: ofa-example
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
config:
server-addr: 10.10.6.66:32725
prefix: ${spring.application.name}
file-extension: yaml
shared-configs:
- data-id: redis-config-local.yml
- data-id: common-config.yml
refresh: true