午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

Springboot apollo原理及使用方法詳解

瀏覽:8日期:2023-05-13 09:54:01

文章背景

如果在spring boot中接入apollo官方文檔:https://github.com/ctripcorp/apollo/wiki使用官方的apollo

演示環(huán)境(Demo):

106.54.227.205賬號(hào)/密碼:apollo/admin

添加配置

Springboot apollo原理及使用方法詳解

spring-boot中如何使用

pom.xml中添加配置

<dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>1.1.0</version></dependency>

配置文件中添加apollo地址

app: id: komilesapollo: meta: http://106.54.227.205:8080 bootstrap: enabled: true namespaces: application

啟動(dòng)類中添加代碼

添加@EnableApolloConfig注解

package com.example.apollodemo; import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication@EnableApolloConfig@MapperScan('com.example.apollodemo.mapper')public class ApolloDemoApplication { public static void main(String[] args) { SpringApplication.run(ApolloDemoApplication.class, args); System.out.println('============ apollo demo application end ============='); }}

controller類新增文件

ApolloController.java

package com.example.apollodemo.controller; import org.springframework.beans.factory.annotation.Value;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController; /** * @author komiles@163.com * @date 2020-05-06 17:28 */@RestController@RequestMapping('/apollo')public class ApolloController { @Value('${name}') private String name; @GetMapping('/name') public String name() { return name; }}

可以讀取到配置為kongming.

數(shù)據(jù)庫配置如何使用?

同理,generatorConfig.xml中也可以讀取數(shù)據(jù)庫配置

<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE generatorConfiguration PUBLIC '-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN' 'http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd'><generatorConfiguration> <context targetRuntime='MyBatis3'> <commentGenerator> <property name='suppressDate' value='false'/> <property name='suppressAllComments' value='true'/> </commentGenerator> <!--目標(biāo)數(shù)據(jù)庫配置--> <jdbcConnection driverClass='com.mysql.jdbc.Driver'connectionURL='${spring.datasource.url}'userId='${spring.datasource.username}'password='${spring.datasource.password}' /> <!-- 指定生成的類型為java類型,避免數(shù)據(jù)庫中number等類型字段 --> <javaTypeResolver> <property name='forceBigDecimals' value='false'/> </javaTypeResolver> <!-- 生成model模型,對(duì)應(yīng)的包,存放位置可以指定具體的路徑,如/ProjectName/src,也可以使用MAVEN來自動(dòng)生成 --> <javaModelGenerator targetPackage='com.example.apollodemo.dao' targetProject='src/main/java'> <property name='enableSubPackages' value='false'/> <property name='trimStrings' value='true'/> <property name='immutable' value='false'/> </javaModelGenerator> <!--對(duì)應(yīng)的xml mapper文件 --> <sqlMapGenerator targetPackage='mapper' targetProject='src/main/resources/mybatis'> <property name='enableSubPackages' value='false'/> </sqlMapGenerator> <!-- 對(duì)應(yīng)的dao接口 --> <javaClientGenerator type='XMLMAPPER' targetPackage='com.example.apollodemo.mapper' targetProject='src/main/java'> <property name='enableSubPackages' value='false'/> </javaClientGenerator> <!--定義需要操作的表及對(duì)應(yīng)的DTO名稱--> <table tableName='t_user' domainObjectName='User'/> </context></generatorConfiguration>

項(xiàng)目demo地址https://github.com/KoMiles/spring-example/tree/master/apollo-demo

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: av免费观看不卡 | 中文字幕第27页 | 黄色高清视频在线观看 | 日本久久精品 | 深夜视频在线播放 | 日韩国产一区 | 日本色综合 | 国产免费美女视频 | 亚洲综合久久av一区二区三区 | 色综合日韩 | 婷婷伊人综合中文字幕 | 国产精品福利在线 | 亚洲人体av | 久久久久久久一 | 米奇狠狠干 | 日韩经典三级 | 天天爱天天操 | 成年人视频网 | 久草香蕉视频 | 三级网站在线免费观看 | 日本免费一区二区三区 | 国产精品视频成人 | 看免费黄色大片 | 午夜视频1000 | 三级福利视频 | 91免费 | 中文永久免费观看 | 成 年人 黄 色 片 | wwwxxx黄色| 亚洲情侣在线 | 一区二区在线看 | 欧美作爱视频 | 青青草福利视频 | 性网站视频| 国产一级片在线播放 | 看特级毛片| 免费色播| 黄色午夜 | 波多野结衣一二区 | 国产在线观看91 | 日韩激情视频在线 |