diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..fc14966b --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..82dbec8a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/oms-api/.gitignore b/oms-api/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/oms-api/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/oms-api/pom.xml b/oms-api/pom.xml new file mode 100644 index 00000000..08c8aacc --- /dev/null +++ b/oms-api/pom.xml @@ -0,0 +1,128 @@ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.2 + + + + + + + + + oms-api + 1.0 + jar + + oms-api + http://maven.apache.org + + + 17 + UTF-8 + UTF-8 + 3.0.2 + 2022.0.0.0 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + junit + junit + 4.13.2 + test + + + org.springframework.cloud + spring-cloud-starter + 4.0.0 + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + 4.0.0 + + + org.springframework.cloud + spring-cloud-loadbalancer + 4.0.0 + + + org.springframework.cloud + spring-cloud-starter-openfeign + 4.0.0 + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + 17 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.example.demo.DemoApplication + true + + + + repackage + + repackage + + + + + + + diff --git a/oms-api/src/main/java/com/qihang/oms/api/Api.java b/oms-api/src/main/java/com/qihang/oms/api/Api.java new file mode 100644 index 00000000..d6e8a1b9 --- /dev/null +++ b/oms-api/src/main/java/com/qihang/oms/api/Api.java @@ -0,0 +1,32 @@ +package com.qihang.oms.api; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.web.client.RestTemplate; + +/** + * Hello world! + * + */ +@EnableFeignClients(basePackages = "com.qihang.oms.api") +@EnableDiscoveryClient +@SpringBootApplication +public class Api +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + SpringApplication.run(Api.class, args); + } + + @Bean + @LoadBalanced + public RestTemplate restTemplate() { + return new RestTemplate(); + } +} diff --git a/oms-api/src/main/java/com/qihang/oms/api/controller/HomeController.java b/oms-api/src/main/java/com/qihang/oms/api/controller/HomeController.java new file mode 100644 index 00000000..3f13234e --- /dev/null +++ b/oms-api/src/main/java/com/qihang/oms/api/controller/HomeController.java @@ -0,0 +1,27 @@ +package com.qihang.oms.api.controller; + +import com.qihang.oms.api.service.EchoService; +import jakarta.annotation.Resource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@RestController +public class HomeController { + @Autowired + private RestTemplate restTemplate; + @Resource + private EchoService echoService; + + @GetMapping(value = "/echo-rest") + public String rest() { + return restTemplate.getForObject("http://tao-oms/test/na", String.class); + } + @GetMapping(value = "/echo-feign") + public String feign() { + return echoService.echo(); + } +} diff --git a/oms-api/src/main/java/com/qihang/oms/api/service/EchoService.java b/oms-api/src/main/java/com/qihang/oms/api/service/EchoService.java new file mode 100644 index 00000000..3e7e4bb2 --- /dev/null +++ b/oms-api/src/main/java/com/qihang/oms/api/service/EchoService.java @@ -0,0 +1,11 @@ +package com.qihang.oms.api.service; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + + +@FeignClient(name = "tao-oms") +public interface EchoService { + @GetMapping(value = "/test/na") + String echo(); +} diff --git a/oms-api/src/main/resources/application.yaml b/oms-api/src/main/resources/application.yaml new file mode 100644 index 00000000..12868fe4 --- /dev/null +++ b/oms-api/src/main/resources/application.yaml @@ -0,0 +1,18 @@ + +spring: + cloud: + loadbalancer: + nacos: + enabled: true + nacos: + serverAddr: 127.0.0.1:8848 + discovery: + server-addr: 127.0.0.1:8848 + config: + import: + - nacos:qihang-oms.yaml?refresh=true + application: + name: oms-api + +server: + port: 8082 \ No newline at end of file diff --git a/oms-api/src/test/java/com/qihang/AppTest.java b/oms-api/src/test/java/com/qihang/AppTest.java new file mode 100644 index 00000000..14e13c7a --- /dev/null +++ b/oms-api/src/test/java/com/qihang/AppTest.java @@ -0,0 +1,38 @@ +package com.qihang; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..6ddbeb04 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + com.qihang + qihang-oms + 1.0-SNAPSHOT + pom + + qihang-oms + http://maven.apache.org + + tao-oms + oms-api + + + + UTF-8 + + + + + + diff --git a/tao-oms/.gitignore b/tao-oms/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/tao-oms/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/tao-oms/pom.xml b/tao-oms/pom.xml new file mode 100644 index 00000000..bfbe9ab1 --- /dev/null +++ b/tao-oms/pom.xml @@ -0,0 +1,101 @@ + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.0.2 + + + + tao-oms + jar + + tao-oms + http://maven.apache.org + + + 17 + UTF-8 + UTF-8 + 3.0.2 + 2022.0.0.0 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + junit + junit + 4.13.2 + test + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + 17 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.example.demo.DemoApplication + true + + + + repackage + + repackage + + + + + + + diff --git a/tao-oms/src/main/java/com/qihang/tao/TaoOmsApplication.java b/tao-oms/src/main/java/com/qihang/tao/TaoOmsApplication.java new file mode 100644 index 00000000..921db162 --- /dev/null +++ b/tao-oms/src/main/java/com/qihang/tao/TaoOmsApplication.java @@ -0,0 +1,21 @@ +package com.qihang.tao; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * Hello world! + * + */ +@EnableDiscoveryClient +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) +public class TaoOmsApplication +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + SpringApplication.run(TaoOmsApplication.class, args); + } +} diff --git a/tao-oms/src/main/java/com/qihang/tao/controller/HomeController.java b/tao-oms/src/main/java/com/qihang/tao/controller/HomeController.java new file mode 100644 index 00000000..a76e7f5c --- /dev/null +++ b/tao-oms/src/main/java/com/qihang/tao/controller/HomeController.java @@ -0,0 +1,23 @@ +package com.qihang.tao.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HomeController { + @GetMapping("/test/22") + public String home(){ + return "hello world"; + } + + @Value(value = "${zhijian.name:1}") + private String serverName; + + @GetMapping(value = "/test/na") + public String get() { + return serverName; + } + +} diff --git a/tao-oms/src/main/resources/application.yaml b/tao-oms/src/main/resources/application.yaml new file mode 100644 index 00000000..ad3d4578 --- /dev/null +++ b/tao-oms/src/main/resources/application.yaml @@ -0,0 +1,14 @@ +spring: + cloud: + nacos: + serverAddr: 127.0.0.1:8848 + discovery: + server-addr: 127.0.0.1:8848 + config: + import: + - nacos:qihang-oms.yaml?refresh=true + application: + name: tao-oms + +server: + port: 8081 \ No newline at end of file diff --git a/tao-oms/src/test/java/com/qihang/AppTest.java b/tao-oms/src/test/java/com/qihang/AppTest.java new file mode 100644 index 00000000..14e13c7a --- /dev/null +++ b/tao-oms/src/test/java/com/qihang/AppTest.java @@ -0,0 +1,38 @@ +package com.qihang; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}