Skip to content

Commit 2989380

Browse files
committed
Spring Boot 项目重构
1 parent 714fce5 commit 2989380

135 files changed

Lines changed: 33914 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>dubbo-spring-boot</artifactId>
7+
<groupId>io.ymq.example</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>dubbo-api</artifactId>
13+
14+
<version>1.0-SNAPSHOT</version>
15+
16+
<packaging>jar</packaging>
17+
18+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.ymq.dubbo.api;
2+
3+
/**
4+
* 描述: 定义服务接口
5+
*
6+
* @author yanpenglei
7+
* @create 2017-10-27 13:20
8+
**/
9+
public interface DemoService {
10+
String sayHello(String name);
11+
}
12+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>dubbo-spring-boot</artifactId>
7+
<groupId>io.ymq.example</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>dubbo-consumer</artifactId>
13+
14+
<packaging>jar</packaging>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>io.ymq.example</groupId>
19+
<artifactId>dubbo-api</artifactId>
20+
<version>${project.parent.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-test</artifactId>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.alibaba</groupId>
33+
<artifactId>dubbo</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.alibaba</groupId>
37+
<artifactId>fastjson</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.javassist</groupId>
41+
<artifactId>javassist</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.apache.zookeeper</groupId>
45+
<artifactId>zookeeper</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.101tec</groupId>
49+
<artifactId>zkclient</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>log4j</groupId>
53+
<artifactId>log4j</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.slf4j</groupId>
57+
<artifactId>slf4j-api</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-autoconfigure</artifactId>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-maven-plugin</artifactId>
70+
</plugin>
71+
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-surefire-plugin</artifactId>
75+
<configuration>
76+
<skip>true</skip>
77+
<testFailureIgnore>true</testFailureIgnore>
78+
</configuration>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
83+
84+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.ymq.dubbo.consumer.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.context.annotation.ImportResource;
5+
import org.springframework.context.annotation.PropertySource;
6+
7+
/**
8+
* 描述: 加载配置
9+
*
10+
* @author yanpenglei
11+
* @create 2017-10-27 13:26
12+
**/
13+
@Configuration
14+
@PropertySource("classpath:dubbo.properties")
15+
@ImportResource({"classpath:dubbo/*.xml"})
16+
public class PropertiesConfig {
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.ymq.dubbo.consumer.run;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ComponentScan;
6+
7+
/**
8+
* 描述: 启动服务
9+
*
10+
* @author yanpenglei
11+
* @create 2017-10-27 11:49
12+
**/
13+
@SpringBootApplication
14+
@ComponentScan(value = {"io.ymq.dubbo"})
15+
public class Startup {
16+
17+
public static void main(String[] args) {
18+
SpringApplication.run(Startup.class, args);
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.ymq.dubbo.consumer.service;
2+
3+
import io.ymq.dubbo.api.DemoService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.stereotype.Service;
6+
7+
/**
8+
* 描述: 消费远程方法
9+
*
10+
* @author yanpenglei
11+
* @create 2017-10-27 13:22
12+
**/
13+
@Service("consumerDemoService")
14+
public class ConsumerDemoService {
15+
16+
@Autowired
17+
private DemoService demoService;
18+
19+
public void sayHello(String name) {
20+
String hello = demoService.sayHello(name); // 执行消费远程方法
21+
System.out.println(hello); // 显示调用结果
22+
}
23+
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spring.application.name=dubbo-consumer
2+
server.port=8085
3+
server.tomcat.max-threads=1000
4+
server.tomcat.max-connections=2000
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#########################################################
2+
# dubbo config
3+
#暴露服务端口
4+
dubbo.protocol.port=20880
5+
#提供方超时时间
6+
dubbo.provider.timeout=10000
7+
#提供方版本
8+
dubbo.provider.version=1.0
9+
#表示该服务使用独的五条条长连
10+
dubbo.provider.connections=5
11+
# 固定大小线程池,启动时建立线程,不关闭,一直持有。(缺省)
12+
dubbo.protocol.threadpool=fixed
13+
# 线程数量
14+
dubbo.protocol.threads=500
15+
#配置重试次数,最好只用于读的重试,写操作可能会引起多次写入 默认retries="0"
16+
dubbo.provider.retries=0
17+
# dubbo缓存文件
18+
dubbo.cache=/data/dubbo/cache/ymq-dubbo-consumer
19+
#########################################################
20+
21+
# zookeeper config
22+
zookeeper.connect=127.0.0.1:2181
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:context="http://www.springframework.org/schema/context"
4+
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
7+
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
8+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
9+
10+
<!-- 增加引用远程服务配置 可以和本地bean一样使用demoService -->
11+
<dubbo:reference id="demoService" check="false" interface="io.ymq.dubbo.api.DemoService"/>
12+
13+
</beans>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:context="http://www.springframework.org/schema/context"
4+
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
7+
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
8+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
9+
10+
<!-- 提供方应用信息,用于计算依赖关系 -->
11+
<dubbo:application name="${spring.application.name}" />
12+
13+
<!-- 使用multicast广播注册中心暴露服务地址 -->
14+
<dubbo:registry protocol="zookeeper" address="${zookeeper.connect}" file="${dubbo.cache}"/>
15+
16+
<!-- 用dubbo协议在20880端口暴露服务 -->
17+
<dubbo:protocol name="dubbo" port="${dubbo.protocol.port}" threadpool="${dubbo.protocol.threadpool}" threads="${dubbo.protocol.threads}"/>
18+
19+
<!-- 提供方的缺省值,当ProtocolConfig和ServiceConfig某属性没有配置时,采用此缺省值,可选。-->
20+
<dubbo:provider connections="${dubbo.provider.connections}" timeout="${dubbo.provider.timeout}" retries="${dubbo.provider.retries}" version="${dubbo.provider.version}" />
21+
22+
<!-- 消费方缺省配置,当ReferenceConfig某属性没有配置时,采用此缺省值,可选。-->
23+
<dubbo:consumer version="${dubbo.provider.version}" />
24+
25+
<!-- 监控中心配置,用于配置连接监控中心相关信息,可选。-->
26+
<dubbo:monitor protocol="registry"/>
27+
28+
</beans>

0 commit comments

Comments
 (0)