Nacos+Springcloud+mybatis-plus+oracle的整合

news2024/12/24 3:42:48

Nacos+Springcloud+mybatis-plus+oracle的整合

1、项目结构在这里插入图片描述

2、父类的依赖

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ycz</groupId>
    <artifactId>Nacos-study</artifactId>
    <packaging>pom</packaging>
    <version>${revision}</version>
    <name>Nacos-study</name>
    <description>Nacos-study</description>
    <properties>
        <!-- 指定项目版本 -->
        <revision>1.0-SNAPSHOT</revision>

        <!-- 指定SpringBoot版本 -->
        <spring-boot.version>2.2.5.RELEASE</spring-boot.version>
        <!-- 指定SpringCloud版本 -->
        <spring-cloud.version>Hoxton.SR3</spring-cloud.version>
        <!-- 指定SpringCloudAlibaba版本 -->
        <spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
        <!-- 指定JDK版本 -->
        <java-jdk.version>1.8</java-jdk.version>
        <!--指定pageHelper-->
        <pageHelper.version>5.3.0</pageHelper.version>
        <!--ojdbc8-->
        <ojdbc8.version>21.8.0.0</ojdbc8.version>
        <!--orai18n-->
        <orai18n.version>19.7.0.0</orai18n.version>
        <!--lombok-->
        <lombok.version>1.18.24</lombok.version>
    </properties>

    <modules>
        <module>nacos-config</module>
        <module>nacos-provider</module>
        <module>nacos-consumer</module>
        <module>nacos-feign-api</module>
        <module>nacos-geteway</module>
        <module>nacos-commons</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <scope>provided</scope>
            </dependency>
            <!-- 声明依赖 springBoot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- 声明依赖 springCloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- 声明依赖 springCloudAlibaba -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
            </dependency>

            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.4.2</version>
            </dependency>

            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper</artifactId>
                <version>${pageHelper.version}</version>
            </dependency>


            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
                <version>${spring-boot.version}</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
            <dependency>
                <groupId>com.oracle.database.jdbc</groupId>
                <artifactId>ojdbc8</artifactId>
                <version>${ojdbc8.version}</version>
            </dependency>

            <dependency>
                <groupId>com.oracle.database.nls</groupId>
                <artifactId>orai18n</artifactId>
                <version>${orai18n.version}</version>
            </dependency>

            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
                <version>1.1.21</version>
            </dependency>



        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>


    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profileActive>dev</profileActive>
            </properties>
        </profile>

        <profile>
            <id>prod</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profileActive>prod</profileActive>
            </properties>
        </profile>

        <profile>
            <id>home</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profileActive>home</profileActive>
            </properties>
        </profile>

    </profiles>



</project>

3、nacos-config

(1)新建一个配置

在这里插入图片描述
在这里插入图片描述

(2)依赖

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.ycz</groupId>
        <artifactId>Nacos-study</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>nacos-config</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>nacos-config</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>8</java.version>
    </properties>
    <dependencies>
        <!-- 父项目中我们已经指定了对应的版本, 这里直接使用就行, 不用在引用版本 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

(3)bootstrap.yml

spring:
  profiles:
    active: @profileActive@

(4)application-dev.yml

server:
  port: 7001
spring:
  application:
    name: nacos-config
  cloud:
    nacos:
      config:
        server-addr: localhost:8848

(5)controller测试

package com.ycz.Controller;

import com.ycz.config.CommonConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class UserController {

    @Autowired
    private CommonConfig config;

    @GetMapping("test")
    public String test(){
        return config.getUsername() + config.getPassword();
    }

}

package com.ycz.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

@RefreshScope
@Component
public class CommonConfig {

    @Value(value = "${oracle.username}")
    private String username;

    @Value(value =  "${oracle.password}")
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

package com.ycz;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class NacosConfigApplication {


    public static void main(String[] args) {


        SpringApplication.run(NacosConfigApplication.class, args);
    }

}

4、nacos-commons

(1)依赖

<?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>Nacos-study</artifactId>
        <groupId>com.ycz</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ycz</groupId>
    <artifactId>nacos-commons</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <name>nacos-commons</name>
    <description>nacos-commons</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>

    </dependencies>



</project>

(2)代码

实体类

@Data
public class HotApps {
    private Integer appOid;

    private String appName;

    private String serviceRyCategoryOid;

    private String appSubName;

    private String businessTag;

}

请求param

@Data
public class HotAppsParams extends BaseParams{

    private Integer appOid;

    private String appName;

    private String serviceRyCategoryOid;

    private String appSubName;

    private String businessTag;

}

5、nacos-provider

(1)依赖

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.ycz</groupId>
        <artifactId>Nacos-study</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>nacos-provider</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>nacos-provider</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>8</java.version>
    </properties>

    <dependencies>
        <!-- 引入commons -->
        <dependency>
            <groupId>com.ycz</groupId>
            <artifactId>nacos-commons</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>


        <!-- 父项目中我们已经指定了对应的版本, 这里直接使用就行, 不用在引用版本 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- 服务注册与发现 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
        </dependency>

        <dependency>
            <groupId>com.oracle.database.nls</groupId>
            <artifactId>orai18n</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>7</source>
                    <target>7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

(2)bootstrap.yml

spring:
  profiles:
    active: @profileActive@

(3)application-dev.yml

server:
  port: 8001
spring:
  application:
    name: nacos-provider
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
#      config:
#        server-addr: localhost:8848
#        file-extension: yaml
  datasource:
    driver-class-name: oracle.jdbc.driver.OracleDriver
    url: jdbc:oracle:thin:@ip:1521:XE
    username: admin
    password: admin
mybatis-plus:
  mapper-locations: classpath*:/mapper/**/*Mapper.xml
  configuration:
    log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl


(3)配置

package com.ycz.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author alex
 * @date 2023/01/13 1:44
 * @Version 1.0
 */
@Configuration
@ConditionalOnClass(value = {PaginationInterceptor.class})
public class MybatisPlusConfig {

    // 最新版
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//        数据库的配置DbType.ORACLE 根据自己的数据库选择
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE));
        return interceptor;
    }

}


mapper

package com.ycz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ycz.entity.HotApps;
import org.springframework.stereotype.Repository;

/**
 * HotAppMapper
 * <p>
 * Description 
 * <p>
 * Creation Time: 2023/1/17 下午3:45
 *
 * @author yang chao zhen
 */
@Repository
public interface HotAppsMapper extends BaseMapper<HotApps> {


}

(4)service

package com.ycz.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ycz.entity.HotApps;
import com.ycz.params.HotAppsParams;

/**
 * HotAppService
 * <p>
 * Description 
 * <p>
 * Creation Time: 2023/1/17 下午3:46
 *
 * @author yang chao zhen
 */
public interface HotAppService {

    IPage<HotApps> getHotApps(HotAppsParams params);

    Object insert(HotApps hotApps);
}

(5)serviceimpl

package com.ycz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycz.entity.HotApps;
import com.ycz.mapper.HotAppsMapper;
import com.ycz.params.HotAppsParams;
import com.ycz.service.HotAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * HotAppService
 * <p>
 * Description
 * <p>
 * Creation Time: 2023/1/17 下午3:46
 *
 * @author yang chao zhen
 */
@Service
public class HotAppServiceImpl implements HotAppService {

    @Autowired
    private HotAppsMapper mapper;

    @Override
    public IPage<HotApps> getHotApps(HotAppsParams params) {
        QueryWrapper<HotApps> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(params.getAppOid()!= null , "APP_OID" ,params.getAppOid());
        return mapper.selectPage(new Page<HotApps>(params.getCurrent(), params.getSize()), queryWrapper);
    }

    @Override
    public Object insert(HotApps hotApps) {
        System.out.println(hotApps);
        return mapper.insert(hotApps);
    }
}

(6)controller

package com.ycz.controller;

import com.ycz.entity.HotApps;
import com.ycz.params.HotAppsParams;
import com.ycz.service.HotAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * HotAppsController
 * <p>
 * Description
 * <p>
 * Creation Time: 2023/1/17 下午3:51
 *
 * @author yang chao zhen
 */
@RequestMapping("/hotApps")
@RestController
public class HotAppsController {

    @Autowired
    private HotAppService service;

    @GetMapping("/page")
    public Object getPage(HotAppsParams params){
        return service.getHotApps(params);
    }

    @PostMapping("/insert")
    public Object insert(HotApps hotApps){
        return service.insert(hotApps);
    }


}

6、naoos-feign-api

(1)依赖

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.ycz</groupId>
        <artifactId>Nacos-study</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>com.ycz</groupId>
    <artifactId>nacos-feign-api</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <name>nacos-feign-api</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <!-- 引入commons -->
        <dependency>
            <groupId>com.ycz</groupId>
            <artifactId>nacos-commons</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

(2)HotAppService

package com.ycz.service;

import com.ycz.params.HotAppsParams;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * HotAppsService
 * <p>
 * Description
 * <p>
 * Creation Time: 2023/1/17 下午3:52
 *
 * @author yang chao zhen
 */
@FeignClient(name = "${nacos.product.name}" , contextId = "hotService")
public interface HotAppsService {

    @GetMapping(path = "/hotApps/page/")
    Object getPage(@SpringQueryMap HotAppsParams params);

    @PostMapping(path = "/hotApps/insert/")
    Object insert(@SpringQueryMap HotAppsParams params);
}

7、nacos-consumer

(1)依赖

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.ycz</groupId>
        <artifactId>Nacos-study</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.ycz</groupId>
    <artifactId>nacos-consumer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>nacos-consumer</name>
    <description>nacos-consumer</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <!-- 引入feign -->
        <dependency>
            <groupId>com.ycz</groupId>
            <artifactId>nacos-feign-api</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <!-- 引入commons -->
        <dependency>
            <groupId>com.ycz</groupId>
            <artifactId>nacos-commons</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <!-- 父项目中我们已经指定了对应的版本, 这里直接使用就行, 不用在引用版本 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- 服务注册与发现 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>

</project>

(2)bootstrap.yml

spring:
  profiles:
    active: @profileActive@

(3)application-dev.yml

server:
  port: 5001
spring:
  application:
    name: nacos-comsumer
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
  datasource:
    driver-class-name: oracle.jdbc.driver.OracleDriver
    url: jdbc:oracle:thin:@127.0.0.1:1521:XE # 假的,为了前面commons里面的@TableName错误
    username: admin
    password: admin

nacos:
  product:
    name: nacos-provider

(4)配置

package com.ycz.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * RestTemplateConfig
 * <p>
 * Description 
 * <p>
 * Creation Time: 2023/1/16 下午12:24
 *
 * @author yang chao zhen
 */
@Configuration
public class RestTemplateConfig {
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

(5)controller

package com.ycz.controller;

import com.ycz.entity.HotApps;
import com.ycz.params.HotAppsParams;
import com.ycz.service.HotAppsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class TestController {
    @Autowired
    private HotAppsService hotAppsService;
    @RequestMapping(value = "/hotApps/page" , method = RequestMethod.GET)
    public Object getPage(HotAppsParams params){
        return hotAppsService.getPage(params);
    }

    @RequestMapping(value = "/hotApps/insert" , method = RequestMethod.POST)
    public Object insert(@RequestBody HotAppsParams params){
        HotApps hotApps = new HotApps();
        BeanUtils.copyProperties(params  , hotApps);
        return hotAppsService.insert(params);
    }

}

8、nacos-geteway

(1)依赖

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.ycz</groupId>
        <artifactId>Nacos-study</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>com.ycz</groupId>
    <artifactId>nacos-geteway</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>nacos-gateway</name>
    <description>nacos-geteway</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!-- 服务注册与发现 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

(2)bootstrap.yml

spring:
  profiles:
    active: @profileActive@

(3)application-dev.yml

spring:
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
      config:
        server-addr: localhost:8848
        enabled: false
    gateway:
      routes:
        - id: user
          uri: lb://nacos-comsumer
          predicates:
            - Path=/gateWay/** #以city开头的请求都负载到consumer服务
          filters:
            - RewritePath=/gateWay/(?<segment>.*), /$\{segment} #过滤掉url里的user,例如http://ip:port/city/getCity -> http://ip:port/getCity
  application:
    name: nacos-gateway
server:
  port: 8000

(4)启动

package com.ycz.nacosgeteway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class NacosGetewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(NacosGetewayApplication.class, args);
    }

}

启动

先启动nacos-config,再nacos-provider,再nacos-consumer,再nacos-geteway

测试

在这里插入图片描述

成功

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/194808.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

shell脚本基本使用

目录 1.是什么&#xff1f; 2.写法 3.shell脚本语法 3.1第一个shell脚本 3.2交互式shell脚本 3.3shell脚本的数值计算 3.4test命令 3.5中括号【】判断符 3.6默认变量 4.shell脚本条件判断 4.1 if fi 4.2 if then else 4.3 if elif else 4.4 case 5.shell脚本函数…

Linux 学习笔记 正则、管道、进程与任务定时

一、筛选与搜索 1.1 grep 命令 筛选数据 grep 是 Globally search a regular expression and print 的缩写。意思是全局搜索一个正则表达式&#xff0c;并且打印。 考虑这样的一个名为 a.txt 的文件&#xff1a; 执行 grep apple ./a.txt 即可匹配所有含有 apple 的字符 默认…

IDEA搭建Finchley.SR2版本的SpringCloud父子基础项目-------zuul和SpringConfig

1.Zuul是什么 Zuul包含了对请求的路由和过滤两个最主要的功能&#xff1a; 其中路由功能负责将外部请求转发到具体的微服务实例上&#xff0c;是实现外部访问统一入口的基础而过滤器功能则负责对请求的处理过程进行干预&#xff0c;是实现请求校验、服务聚合等功能的基础. Zu…

4款实用的办公软件,每一款都让你效率翻倍,相见不易

称心的电脑使用体验&#xff0c;总离不开实用的工具&#xff0c;一款高效的工具&#xff0c;能让你的办公体验翻倍。 1、Mem Reduct 这是一款强大到离谱的电脑清理工具&#xff0c;比某安全卫士实用多&#xff0c;没有任何弹屏广告&#xff0c;完全免费使用&#xff0c;内存清理…

搜索算法基础

一 DFS 深度优先搜索算法&#xff08;Depth First Search&#xff0c;简称DFS&#xff09;&#xff1a;一种用于遍历或搜索树或图的算法。 沿着树的深度遍历树的节点&#xff0c;尽可能深的搜索树的分支。当节点v的所在边都己被探寻过或者在搜寻时结点不满足条件&#xff0c;搜…

uboot的烧写及使用

目录 一、uboot概述 Bootloader Bootloader基本功能 常见的Bootloader 二、SD卡启动盘制作 三、uboot的使用 3.1uboot模式 3.2uboot帮助命令 3.3uboot环境变量命令 3.4常用环境变量 3.5网络传输命令 3.6u-boot访问存储器命令 3.7 u-boot自启动环境变量&#xff08…

人工智能趋势——2023 年综述

随着DALLE 2 于 2022 年 4 月的宣布&#xff0c;关于2022 年初第三个 AI 冬天——或 AI 撞墙——的预言过时得很快而且效果不佳&#xff0c;随后出现了更多主要由扩散模型驱动的文本到图像应用程序&#xff0c;这是一个非常多产的领域用于计算机视觉研究及其他领域。AI 的 2022…

SpringCloud五大核心组件

Consul 等&#xff0c;提供了搭建分布式系统及微服务常用的工具&#xff0c;如配置管理、服务发现、断路器、智能路由、微代理、控制总线、一次性token、全局锁、选主、分布式会话和集群状态等&#xff0c;满足了构建微服务所需的所有解决方案。 服务发现——Netflix Eureka …

六百亿流量、25万出场费,袁树雄身价是《汉川》杨语莲125倍

在文章开始之前&#xff0c;咱们不妨先看两组数据&#xff0c;第一组数据是六百个亿&#xff0c;第二组数据则是二十五万。乍一看并没有什么特别&#xff0c;但是要把这两组数据&#xff0c;和一名音乐人联系起来的话&#xff0c;就会产生非常神奇的效果。 《早安隆回》的创作者…

[oeasy]python0070_ 字体样式_下划线_中划线_闪动效果_反相_取消效果

字体样式 回忆上次内容 m 可以改变字体样式 0-10 之间设置的都是字体效果 0 复原1 变亮2 变暗 从3到10 又是什么效果 呢&#xff1f;&#xff1f;真的可以blink闪烁吗&#xff1f;&#x1f441; 3m 3m 实现斜体字的效果 4m 4m 对应着下划线 控制范围 通过控制字符串的位置…

DNS服务解析与原理笔记

引言DNS介绍DNS原理与解析DNS查询DNS服务搭建DNS劫持和污染计算机面试 or 真题DNS应用扩展参考与推荐引言 我想很多人遇到过这样一种情况&#xff0c;电脑突然上不了网了&#xff0c;或者说可以登陆QQ&#xff0c;但是进不了网页&#xff0c;任何网页都会出现如下的类似截图&a…

Android.mk文件编写

来源&#xff1a;https://www.jianshu.com/p/9aab51f4cd6f 1. Android.mk 介绍 Android.mk 是Android 提供的一种makefile 文件&#xff0c;注意用来编译生成 exe(二进制可执行文件)、so(动态库文件)、a(静态库文件)、jar(jar包) 和 apk 等文件。Android.mk和一个或多个.c的源…

PWN入门程序装载与虚拟内存 小白笔记

1.源代码到执行源代码test.c从磁盘中&#xff0c;通过gcc编译成a.out&#xff08;可执行文件&#xff09;。执行的时候&#xff0c;是将磁盘中的可执行文件&#xff08;a.out&#xff09;映像到内存中。2.节视图和段视图节视图&#xff08;磁盘中的可执行文件&#xff09;不同的…

采用消息中间件实现最终一致性的分布式事务

基于可靠消息服务的方案是通过消息中间件保证上下游应用数据操作的一致性。假设有A和B两个系统&#xff0c;分别可以处理任务A和任务B。此时存在一个业务流程&#xff0c;需要将任务A和任务B在同一个事务中处理。就可以使用消息中间件来实现这种分布式事务。 第一步&#xff…

一篇文章带你了解KendoReact DateRangePicker,让日期选择变得更酷炫!

Kendo UI致力于新的开发&#xff0c;来满足不断变化的需求。现在我们非常自豪地宣布&#xff0c;通过React框架的Kendo UI JavaScript封装来支持React Javascript框架。KendoReact能够为客户提供更好的用户体验&#xff0c;并且能够更快地构建更好的应用程序。理想情况下&#…

python中有哪些运算符,python里的运算符号

大家好&#xff0c;给大家分享一下python中有哪些运算符&#xff0c;很多人还不知道这一点。下面详细解释一下。现在让我们来看看&#xff01; 1、Python中的算术运算符有哪些呢&#xff1f; 1. 比较运算符&#xff1a; 如果比较式成立&#xff0c;返回True&#xff1b;不成立…

[Linux系列]linux bond详解

目录 背景 简介 bond分类 1. mode0(balance-rr) 2. mode1 (active-backup) 3. mode2&#xff08;balance-xor&#xff09; 4. mode3&#xff08;broadcast&#xff09; 5. mode4&#xff08;802.3ad&#xff09; 6. mode5&#xff08;balance-tlb&#xff09;…

STL模拟实现——stack、queue和priority_queue(适配器、仿函数、反向迭代器)

适配器 适配器是一种设计模式(设计模式是一套被反复使用的、多数人知晓的、经过分类编目的、代码设计经验的总 结)&#xff0c;该种模式是将一个类的接口转换成客户希望的另外一个接口。下列的这些stack、queue和priority_queue以及反向迭代器都是适配器。 stack介绍 1. sta…

数据结构-第八期——树状数组-原理区间和

目录 1、树状数组 2、基本应用 2.1、前缀和&#xff1a;不修改&#xff0c;只查询 2.2、树状数组&#xff1a;动态修改&#xff0c;求区间和 3、实现数组树状 3.1、神奇的lowbit (x)操作 3.2、tree[ ]数组 3.3、基于tree[ ]的计算 3.4 sum[]的计算 3.5、tree[]的更新…

CD3药物研发进展-销售数据-上市药品前景分析

CD3作为近几年的双抗热门靶点之一&#xff0c;目前在全球登记的CD3相关药物就有470个&#xff0c;上市的CD3药物有8款&#xff0c;Ⅰ期临床到Ⅲ期临床有116种&#xff0c;临床前及药物发现达200多种&#xff0c;其火热程度可想而知&#xff0c;笔者为方便大家更加清晰了解CD3在…