订单模块调用库存模块
package com.java1234.controller;
import com.java1234.feign.StockFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping( "/order" )
public class OrderController {
@Autowired
private StockFeignService stockFeignService;
@RequestMapping( "/test" )
public String test ( ) {
return stockFeignService.test( "牛逼" ) ;
}
}
package com.java1234.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient( "nacos-stock" )
public interface StockFeignService {
@RequestMapping( "/stock/test" )
public String test( @RequestParam( "info" ) String info) ;
}
package com.java1234;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients( basePackages = "com.java1234.feign" )
public class NacosOrderApplication {
public static void main( String[ ] args) {
SpringApplication.run( NacosOrderApplication.class,args) ;
}
}
server:
port: 8082
servlet:
context-path: /
spring:
application:
name: nacos-order
cloud:
nacos:
discovery:
server-addr: 127.0 .0.1:8848
< ?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_demo< /artifactId>
< groupId> com.java.1234 < /groupId>
< version> 1.0 -SNAPSHOT< /version>
< /parent>
< modelVersion> 4.0 .0 < /modelVersion>
< artifactId> nacos-order< /artifactId>
< properties>
< maven.compiler.source> 8 < /maven.compiler.source>
< maven.compiler.target> 8 < /maven.compiler.target>
< /properties>
< dependencies>
< 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>
< ! -- 服务注册/发现-->
< dependency>
< groupId> com.alibaba.cloud< /groupId>
< artifactId> spring-cloud-starter-alibaba-nacos-discovery< /artifactId>
< /dependency>
< ! -- openfeign -->
< dependency>
< groupId> org.springframework.cloud< /groupId>
< artifactId> spring-cloud-starter-openfeign< /artifactId>
< /dependency>
< /dependencies>
< /project>
package com.java1234.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping( "/stock" )
public class StockController {
@RequestMapping( "/test" )
public String test( String info) {
return "库存模块接收到的信息:" +info;
}
}
package com.java1234;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class NacosStockApplication {
public static void main( String[ ] args) {
SpringApplication.run( NacosStockApplication.class,args) ;
}
}
server:
port: 8084
servlet:
context-path: /
spring:
application:
name: nacos-stock
cloud:
nacos:
discovery:
server-addr: 127.0 .0.1:8848
< ?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_demo< /artifactId>
< groupId> com.java.1234 < /groupId>
< version> 1.0 -SNAPSHOT< /version>
< /parent>
< modelVersion> 4.0 .0 < /modelVersion>
< artifactId> nacos-stock< /artifactId>
< properties>
< maven.compiler.source> 8 < /maven.compiler.source>
< maven.compiler.target> 8 < /maven.compiler.target>
< /properties>
< dependencies>
< 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>
< ! -- 服务注册/发现-->
< dependency>
< groupId> com.alibaba.cloud< /groupId>
< artifactId> spring-cloud-starter-alibaba-nacos-discovery< /artifactId>
< /dependency>
< /dependencies>
< /project>