<!-- 版本管理設定 -->
<properties>
<!--依賴管理-->
<spring-boot-dependencies.version>2.2.6.RELEASE</spring-boot-dependencies.version>
<spring-cloud-alibaba-dependencies.version>2.2.1.RELEASE</spring-cloud-alibaba-dependencies.version>
<spring-cloud-dependencies.version>Hoxton.SR6</spring-cloud-dependencies.version>
<spring-security-oauth2.version>2.3.6.RELEASE</spring-security-oauth2.version>
<spring-boot-starter-jdbc.version>2.2.6.RELEASE</spring-boot-starter-jdbc.version>
<alicloud-oss.version>2.2.0.RELEASE</alicloud-oss.version>
<!-- commons-utits 版本依賴管理-->
<fastjson.version>1.2.68</fastjson.version>
<httpclient.version>4.5.12</httpclient.version>
<commons-io.version>2.7</commons-io.version>
<commons-lang3.version>3.10</commons-lang3.version>
<commons-codec.version>1.14</commons-codec.version>
<!--service-utils 版本依賴管理-->
<mybatisPlus.version>3.3.1.tmp</mybatisPlus.version>
<mysql.version>5.1.48</mysql.version>
<lombok.version>1.18.12</lombok.version>
<druid.version>1.1.17</druid.version>
<!--controller 版本依賴管理-->
<swagger.version>2.9.2</swagger.version>
<swagger-ui.version>2.9.2</swagger-ui.version>
<!--maven編譯外掛版本jdk8-->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<!-- 依賴管理-->
<dependencyManagement>
<dependencies>
<!-- spring-cloud 阿里巴巴依賴管理 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- spring-cloud-starter-alicloud-oss OSS物件儲存服務-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
<version>${alicloud-oss.version}</version>
</dependency>
<!-- spring-boot下所有版本依賴的管理 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- spring-cloud-dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- fastjson Json工具包 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- commons-io 檔案流工具包 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<!-- commons-lang3 字串工具包 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<!-- commons-codec 加密解密工具包 包含常見的編碼解碼工具Base64、MD5、Hex、SHA1、DES等-->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<!-- httpclient Http工具包-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<!--controller模組依賴管理-->
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger-ui.version}</version>
</dependency>
<!--service模組依賴管理-->
<!-- mybatisPlus 啟動器-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatisPlus.version}</version>
</dependency>
<!-- mysql jdbc連線 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--lombok 自動生成get set toString等方法簡化類程式碼-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!-- druid 資料庫連線池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- maven編譯外掛 限定jdk8進行編譯專案 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
nacos的properties/yml設定資訊的填寫建議直接看官方檔案:https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
properties檔案
server.port=8070
spring.application.name=server-provider
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
啟動類,有一個Controller
@SpringBootApplication
@EnableDiscoveryClient
public class NacosProviderApplication {
public static void main(String[] args) {
SpringApplication.run(NacosProviderApplication.class, args);
}
@RestController
class EchoController {
@RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
public String echo(@PathVariable String string) {
return "Hello Nacos Discovery " + string;
}
}
}
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
nacos設定需要在啟動的時候就載入設定因此,
需要使用bootstrap.properties / bootstrap.yml
提前在nacos依賴生效前就將設定獲取到
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.application.name=example
檢測設定管理是否生效直接看檔案中的說明
https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html