diff --git a/README.md b/README.md index eee78e4..d2cddef 100644 --- a/README.md +++ b/README.md @@ -4,37 +4,51 @@ spring boot 学习系列 (使用版本 1.5.3) -> * 1.chapter1> springboot 项目结构解析 -> * 2.chapter2> 配置文件详解:自定义属性、随机数、多环境配置等(目前只使用properties,后续添加yml的配置方式用法) -> * 3.chapter3> spring boot 构建restful api以及单元测试,替换默认json 解析框架,使用fastjson -> * 4.chapter3-jersey> springboot 整合jersey 实现restful. -> * 5.chapter4-thymeleaf> spring boot 国际化相关处理和thymeleaf 模板语法的基本使用 -> * 6.chapter4-freemarker> 使用freemarker模板引擎 -> * 7.chapter4-jsp> spring boot 对jsp 的支持 -> * 8.chapter4-velocity> spring boot 使用velocity 版本情况说明 -> * 9.chapter5-swagger> spring boot 使用swagger构建restful api -> * 10.chapter6-handle-exception> spring boot 统一异常处理(返回异常对象json 或者modelandview) -> * 11.chapter6-servlet> spring boot 下使用servlet、filter、listener以及springmvc interceptor 的相关处理. -> * 12.chapter6-aop-log> spring boot log4j 使用aop方式添加日志. -> * 13.chapter7-jdbctemplate> spring boot 整合jdbctemplate 操作数据库. -> * 14.chapter7-spring-data-jpa> spring boot 整合spring data jpa ,简化数据库操作 -> * 15.chapter7-mybatis> spring boot 整合mybatis 使用,提供两种方式:xml 和annotation的方式。 -> * 16.chapter7-mybatis-mapper-plugin> spring boot 整合mybatis 第三方mapper 插件、mybatis自动生成工具 generator 简化开发. -> * 17.chapter8-jdbctemplate-mutil-datasource> spring boot 整合jdbctemplate 多数据源 -> * 18.chapter8-jpa-mutil-datasource> spring boot 整合spring data jpa 多数据源 -> * 19.chapter8-mybatis-mutil-datasource> spring boot 使用druid 数据源 整合mybatis 多数据源 -> * 20.chapter9-redis> spring boot 整合redis -> * 21.chapter9-redis-cache> spring boot 使用redis 作为缓存实例 -> * 22.chapter9-redis-cluster> 添加了注释说明了JedisCluster 与RedisTemplate 操作RedisCluster 的一些使用原理 . -> * 23.chapter9-redis-session> spring boot 整合Redis . -> * 24.chapter10-shiro> spring boot 整合shiro 基本实例 -> * 25.chapter10-jwt> spring boot 整合jwt 实现token 认证. -> * 26.chapter10-security> spring boot 整合security 实现简单权限控制. -> * 27.chapter10-security-jwt> spring boot security token 整合实现认证登陆. -> * 28.chapter11-caching-ehcache> spring boot框架缓存系列 ehcache . -> * 29.chapter11-caching-redis> redis 使用annotation 方式实现cache . -> * 30.chapter12-rocketmq> spring boot 整合rocketmq 测试. +- [x] 1.chapter1 -- springboot 项目结构解析 +- [x] 2.chapter2 -- 配置文件详解:自定义属性、随机数、多环境配置等(目前只使用properties,后续添加yml的配置方式用法) +- [x] 3.chapter3 -- spring boot 构建restful api以及单元测试,替换默认json 解析框架,使用fastjson +- [x] 4.chapter3-jersey -- springboot 整合jersey 实现restful. +- [x] 5.chapter4-thymeleaf -- spring boot 国际化相关处理和thymeleaf 模板语法的基本使用 +- [x] 6.chapter4-freemarker -- 使用freemarker模板引擎 +- [x] 7.chapter4-jsp -- spring boot 对jsp 的支持 +- [x] 8.chapter4-velocity -- spring boot 使用velocity 版本情况说明 +- [x] 9.chapter5-swagger -- spring boot 使用swagger构建restful api +- [x] 10.chapter6-handle-exception -- spring boot 统一异常处理(返回异常对象json 或者modelandview) +- [x] 11.chapter6-servlet -- spring boot 下使用servlet、filter、listener以及springmvc interceptor 的相关处理. +- [x] 12.chapter6-aop-log -- spring boot log4j 使用aop方式添加日志. +- [x] 13.chapter7-jdbctemplate -- spring boot 整合jdbctemplate 操作数据库. +- [x] 14.chapter7-spring-data-jpa -- spring boot 整合spring data jpa ,简化数据库操作 +- [x] 15.chapter7-mybatis -- spring boot 整合mybatis 使用,提供两种方式:xml 和annotation的方式。 +- [x] 16.chapter7-mybatis-mapper-plugin -- spring boot 整合mybatis 第三方mapper 插件、mybatis自动生成工具 generator 简化开发. +- [x] 17.chapter8-jdbctemplate-mutil-datasource -- spring boot 整合jdbctemplate 多数据源 +- [x] 18.chapter8-jpa-mutil-datasource -- spring boot 整合spring data jpa 多数据源 +- [x] 19.chapter8-mybatis-mutil-datasource -- spring boot 使用druid 数据源 整合mybatis 多数据源 +- [x] 20.chapter9-redis -- spring boot 整合redis +- [x] 21.chapter9-redis-cache -- spring boot 使用redis 作为缓存实例 +- [x] 22.chapter9-redis-cluster -- 添加了注释说明了JedisCluster 与RedisTemplate 操作RedisCluster 的一些使用原理 . +- [x] 23.chapter9-redis-session -- spring boot 整合Redis . +- [x] 24.chapter10-shiro -- spring boot 整合shiro 基本实例 +- [x] 25.chapter10-jwt -- spring boot 整合jwt 实现token 认证. +- [x] 26.chapter10-security -- spring boot 整合security 实现简单权限控制. +- [x] 27.chapter10-security-jwt -- spring boot security token 整合实现认证登陆. +- [x] 28.chapter11-caching-ehcache -- spring boot框架缓存系列 ehcache . +- [x] 29.chapter11-caching-redis -- redis 使用annotation 方式实现cache . +- [x] 30.chapter12-rocketmq -- spring boot 整合rocketmq 测试. +- [x] 31.chapter12-dubbo -- spring boot 整合dubbo两种使用方式. +## 测试运行 +``` +git clone https://github.com/t-hong/vue2-manage.git + +jdk8 + +更新所有maven 依赖 + +各个模块相对独立,可直接运行spring boot 启动类(推荐) 或者加入tomcat运行的方式 + +注意:部分模块需要第三方服务的,一定要检查配置连接是否正确 + +``` ## 后续计划... * 日志系列: * Log4J2 diff --git a/chapter10-security-oauth2.0/src/main/java/com/hong/security/SecurityConfig.java b/chapter10-security-oauth2.0/src/main/java/com/hong/security/SecurityConfig.java index 3d687db..98a2a07 100644 --- a/chapter10-security-oauth2.0/src/main/java/com/hong/security/SecurityConfig.java +++ b/chapter10-security-oauth2.0/src/main/java/com/hong/security/SecurityConfig.java @@ -10,7 +10,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; import org.springframework.security.oauth2.client.OAuth2ClientContext; import org.springframework.security.oauth2.client.OAuth2RestTemplate; import org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter; @@ -26,6 +25,7 @@ * security 项目安全的配置. * Created by hong on 2017/7/10. */ +@SuppressWarnings("ALL") @EnableWebSecurity @EnableOAuth2Client // 启用 OAuth 2.0 客户端 @EnableGlobalMethodSecurity(prePostEnabled = true) // 启用方法安全设置 @@ -43,6 +43,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { */ @Override protected void configure(HttpSecurity http) throws Exception { + //noinspection AlibabaAvoidCommentBehindStatement http.addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class) .antMatcher("/**") .authorizeRequests() diff --git a/springboot-dubbo/dubbo-client/pom.xml b/chapter13-dubbo/dubbo-client/pom.xml similarity index 59% rename from springboot-dubbo/dubbo-client/pom.xml rename to chapter13-dubbo/dubbo-client/pom.xml index eac5a2d..ed21e7a 100644 --- a/springboot-dubbo/dubbo-client/pom.xml +++ b/chapter13-dubbo/dubbo-client/pom.xml @@ -16,6 +16,19 @@ dubbo-interface 1.0-SNAPSHOT + + + + io.dubbo.springboot + spring-boot-starter-dubbo + ${dubbo-spring-boot} + diff --git a/springboot-dubbo/dubbo-client/src/main/java/org/hong/dubbo/DubboClientApplication.java b/chapter13-dubbo/dubbo-client/src/main/java/org/hong/dubbo/DubboClientApplication.java similarity index 88% rename from springboot-dubbo/dubbo-client/src/main/java/org/hong/dubbo/DubboClientApplication.java rename to chapter13-dubbo/dubbo-client/src/main/java/org/hong/dubbo/DubboClientApplication.java index 2ef0649..a2ba86b 100644 --- a/springboot-dubbo/dubbo-client/src/main/java/org/hong/dubbo/DubboClientApplication.java +++ b/chapter13-dubbo/dubbo-client/src/main/java/org/hong/dubbo/DubboClientApplication.java @@ -11,7 +11,7 @@ public class DubboClientApplication { public static void main(String[] args) { ConfigurableApplicationContext run = SpringApplication.run(DubboClientApplication.class, args); TestService helloService = run.getBean(TestService.class); - String hello = helloService.hello(); + String hello = helloService.hello("spring-boot-starter-dubbo"); System.out.println(hello); } } diff --git a/springboot-dubbo/dubbo-client/src/main/java/org/hong/dubbo/service/TestService.java b/chapter13-dubbo/dubbo-client/src/main/java/org/hong/dubbo/service/TestService.java similarity index 76% rename from springboot-dubbo/dubbo-client/src/main/java/org/hong/dubbo/service/TestService.java rename to chapter13-dubbo/dubbo-client/src/main/java/org/hong/dubbo/service/TestService.java index 7b28663..dc42175 100644 --- a/springboot-dubbo/dubbo-client/src/main/java/org/hong/dubbo/service/TestService.java +++ b/chapter13-dubbo/dubbo-client/src/main/java/org/hong/dubbo/service/TestService.java @@ -9,7 +9,7 @@ public class TestService { @Reference(version = "1.0.0") public HelloService helloService; - public String hello() { - return helloService.hello() ; + public String hello(String msg) { + return helloService.hello(msg) ; } } diff --git a/springboot-dubbo/dubbo-client/src/main/resources/application.properties b/chapter13-dubbo/dubbo-client/src/main/resources/application.properties similarity index 100% rename from springboot-dubbo/dubbo-client/src/main/resources/application.properties rename to chapter13-dubbo/dubbo-client/src/main/resources/application.properties diff --git a/springboot-dubbo/dubbo-interface/pom.xml b/chapter13-dubbo/dubbo-interface/pom.xml similarity index 100% rename from springboot-dubbo/dubbo-interface/pom.xml rename to chapter13-dubbo/dubbo-interface/pom.xml diff --git a/springboot-dubbo/dubbo-interface/src/main/java/org/hong/dubbo/service/HelloService.java b/chapter13-dubbo/dubbo-interface/src/main/java/org/hong/dubbo/service/HelloService.java similarity index 84% rename from springboot-dubbo/dubbo-interface/src/main/java/org/hong/dubbo/service/HelloService.java rename to chapter13-dubbo/dubbo-interface/src/main/java/org/hong/dubbo/service/HelloService.java index 506a5d5..b12afd0 100644 --- a/springboot-dubbo/dubbo-interface/src/main/java/org/hong/dubbo/service/HelloService.java +++ b/chapter13-dubbo/dubbo-interface/src/main/java/org/hong/dubbo/service/HelloService.java @@ -9,5 +9,5 @@ */ public interface HelloService { - String hello(); + String hello(String msg); } diff --git a/springboot-dubbo/dubbo-server/pom.xml b/chapter13-dubbo/dubbo-server/pom.xml similarity index 60% rename from springboot-dubbo/dubbo-server/pom.xml rename to chapter13-dubbo/dubbo-server/pom.xml index db6cfe0..f7a7b3a 100644 --- a/springboot-dubbo/dubbo-server/pom.xml +++ b/chapter13-dubbo/dubbo-server/pom.xml @@ -16,15 +16,20 @@ dubbo-interface ${project.parent.version} + + + + io.dubbo.springboot + spring-boot-starter-dubbo + ${dubbo-spring-boot} + - - - - org.springframework.boot - spring-boot-maven-plugin - - - \ No newline at end of file diff --git a/springboot-dubbo/dubbo-server/src/main/java/org/hong/dubbo/DubboServerApplication.java b/chapter13-dubbo/dubbo-server/src/main/java/org/hong/dubbo/DubboServerApplication.java similarity index 100% rename from springboot-dubbo/dubbo-server/src/main/java/org/hong/dubbo/DubboServerApplication.java rename to chapter13-dubbo/dubbo-server/src/main/java/org/hong/dubbo/DubboServerApplication.java diff --git a/springboot-dubbo/dubbo-server/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java b/chapter13-dubbo/dubbo-server/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java similarity index 78% rename from springboot-dubbo/dubbo-server/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java rename to chapter13-dubbo/dubbo-server/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java index e85cb5d..e2642f1 100644 --- a/springboot-dubbo/dubbo-server/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java +++ b/chapter13-dubbo/dubbo-server/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java @@ -13,7 +13,7 @@ public class HelloServiceImpl implements HelloService { @Override - public String hello() { - return "hello springboot dubbo"; + public String hello(String msg) { + return "hello springboot: "+msg; } } diff --git a/springboot-dubbo/dubbo-server/src/main/resources/application.properties b/chapter13-dubbo/dubbo-server/src/main/resources/application.properties similarity index 100% rename from springboot-dubbo/dubbo-server/src/main/resources/application.properties rename to chapter13-dubbo/dubbo-server/src/main/resources/application.properties diff --git a/chapter13-dubbo/dubbo-xml-consumer/pom.xml b/chapter13-dubbo/dubbo-xml-consumer/pom.xml new file mode 100644 index 0000000..cd57ad6 --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-consumer/pom.xml @@ -0,0 +1,43 @@ + + + + springboot-dubbo + com.hong + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-xml-consumer + + + + com.hong + dubbo-interface + ${project.parent.version} + + + + + + com.alibaba + dubbo + 2.5.3 + + + org.springframework + spring + + + + + + + com.github.sgroschupf + zkclient + 0.1 + + + + \ No newline at end of file diff --git a/chapter13-dubbo/dubbo-xml-consumer/src/main/java/org/hong/dubbo/Application.java b/chapter13-dubbo/dubbo-xml-consumer/src/main/java/org/hong/dubbo/Application.java new file mode 100644 index 0000000..3fe67e0 --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-consumer/src/main/java/org/hong/dubbo/Application.java @@ -0,0 +1,19 @@ +package org.hong.dubbo; + + +import org.hong.dubbo.service.HelloService; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ImportResource; + +@SpringBootApplication +@ImportResource({"classpath:spring-dubbo.xml"}) +public class Application { + + public static void main(String[] args) { + ConfigurableApplicationContext run = SpringApplication.run(Application.class, args); + HelloService helloService = run.getBean(HelloService.class); + System.out.println(helloService.hello("xml")); + } +} diff --git a/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/application.properties b/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/application.properties new file mode 100644 index 0000000..c5bdecd --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/application.properties @@ -0,0 +1 @@ +server.post=8083 diff --git a/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/dubbo.properties b/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/dubbo.properties new file mode 100644 index 0000000..25ed708 --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/dubbo.properties @@ -0,0 +1 @@ +appname=dubbo-consumer diff --git a/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/spring-dubbo.xml b/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/spring-dubbo.xml new file mode 100644 index 0000000..aea148b --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-consumer/src/main/resources/spring-dubbo.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/chapter13-dubbo/dubbo-xml-provider/pom.xml b/chapter13-dubbo/dubbo-xml-provider/pom.xml new file mode 100644 index 0000000..880a8ca --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-provider/pom.xml @@ -0,0 +1,43 @@ + + + + springboot-dubbo + com.hong + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-xml-provider + + + + com.hong + dubbo-interface + ${project.parent.version} + + + + + com.alibaba + dubbo + 2.5.3 + + + org.springframework + spring + + + + + + + com.github.sgroschupf + zkclient + 0.1 + + + + + \ No newline at end of file diff --git a/chapter13-dubbo/dubbo-xml-provider/src/main/java/org/hong/dubbo/Application.java b/chapter13-dubbo/dubbo-xml-provider/src/main/java/org/hong/dubbo/Application.java new file mode 100644 index 0000000..31cfb00 --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-provider/src/main/java/org/hong/dubbo/Application.java @@ -0,0 +1,18 @@ +package org.hong.dubbo; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; + +/** + * spring boot 启动类. + */ +@SpringBootApplication +@ImportResource(locations={"classpath:spring-dubbo.xml"}) +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/chapter13-dubbo/dubbo-xml-provider/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java b/chapter13-dubbo/dubbo-xml-provider/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java new file mode 100644 index 0000000..9a57e14 --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-provider/src/main/java/org/hong/dubbo/service/HelloServiceImpl.java @@ -0,0 +1,13 @@ +package org.hong.dubbo.service; + + +import org.springframework.stereotype.Service; + +@Service("helloService") +public class HelloServiceImpl implements HelloService{ + + @Override + public String hello(String msg) { + return "spring boot dubbo: "+msg; + } +} diff --git a/chapter13-dubbo/dubbo-xml-provider/src/main/resources/application.properties b/chapter13-dubbo/dubbo-xml-provider/src/main/resources/application.properties new file mode 100644 index 0000000..58baa02 --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-provider/src/main/resources/application.properties @@ -0,0 +1,4 @@ + + + +server.port=8082 diff --git a/chapter13-dubbo/dubbo-xml-provider/src/main/resources/dubbo.properties b/chapter13-dubbo/dubbo-xml-provider/src/main/resources/dubbo.properties new file mode 100644 index 0000000..29d8920 --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-provider/src/main/resources/dubbo.properties @@ -0,0 +1,2 @@ +appname=dubbo-provider +port=20880 diff --git a/chapter13-dubbo/dubbo-xml-provider/src/main/resources/spring-dubbo.xml b/chapter13-dubbo/dubbo-xml-provider/src/main/resources/spring-dubbo.xml new file mode 100644 index 0000000..7dcadf2 --- /dev/null +++ b/chapter13-dubbo/dubbo-xml-provider/src/main/resources/spring-dubbo.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/springboot-dubbo/pom.xml b/chapter13-dubbo/pom.xml similarity index 74% rename from springboot-dubbo/pom.xml rename to chapter13-dubbo/pom.xml index b30271b..f4233ee 100644 --- a/springboot-dubbo/pom.xml +++ b/chapter13-dubbo/pom.xml @@ -15,22 +15,14 @@ dubbo-interface dubbo-server dubbo-client + dubbo-xml-provider + dubbo-xml-consumer 1.0.0 - - - io.dubbo.springboot - spring-boot-starter-dubbo - ${dubbo-spring-boot} - - junit diff --git a/chapter7-mybatis/src/main/java/com/hong/mapper/UserMapper.java b/chapter7-mybatis/src/main/java/com/hong/mapper/UserMapper.java index e6432bf..ab31715 100644 --- a/chapter7-mybatis/src/main/java/com/hong/mapper/UserMapper.java +++ b/chapter7-mybatis/src/main/java/com/hong/mapper/UserMapper.java @@ -29,8 +29,6 @@ public interface UserMapper { * 具体详解请查看:http://www.mybatis.org/mybatis-3/zh/java-api.html */ - - /** 返回结果的绑定 ,通过@Results 和@Result 来绑定 * 通过情况下,没有配置的话,字段不相同的就不会对应上,同时如果配置了结果绑定时,部分字段没有对应的话,那么对应字段的值为null * **/ diff --git a/pom.xml b/pom.xml index 23576d4..b332446 100644 --- a/pom.xml +++ b/pom.xml @@ -39,9 +39,9 @@ chapter10-security-jwt chapter10-security-oauth2.0 chapter11-caching-ehcache - chapter12-rocketmq chapter11-caching-redis - springboot-dubbo + chapter12-rocketmq + chapter13-dubbo diff --git a/springboot.xmind b/springboot.xmind index 9d927fb..35e1a65 100644 Binary files a/springboot.xmind and b/springboot.xmind differ