├── README.md ├── SpringBoot+SpringCloud ├── consumer-user │ ├── consumer-user.iml │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── cloud │ │ │ │ │ └── consumer │ │ │ │ │ ├── ConsumerApplication.java │ │ │ │ │ └── controller │ │ │ │ │ └── UserController.java │ │ │ └── resources │ │ │ │ └── application.yml │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── consumer │ │ │ └── ConsumerApplicationTests.java │ └── target │ │ ├── classes │ │ ├── application.yml │ │ └── com │ │ │ └── cloud │ │ │ └── consumer │ │ │ ├── ConsumerApplication.class │ │ │ └── controller │ │ │ └── UserController.class │ │ └── test-classes │ │ └── com │ │ └── cloud │ │ └── consumer │ │ └── ConsumerApplicationTests.class ├── eureka-server │ ├── eureka-server.iml │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── cloud │ │ │ │ │ └── eureka │ │ │ │ │ └── EurekaServerApplication.java │ │ │ └── resources │ │ │ │ └── application.yml │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── cloud │ │ │ └── eureka │ │ │ └── EurekaServerApplicationTests.java │ └── target │ │ ├── classes │ │ ├── application.yml │ │ └── com │ │ │ └── cloud │ │ │ └── eureka │ │ │ └── EurekaServerApplication.class │ │ └── test-classes │ │ └── com │ │ └── cloud │ │ └── eureka │ │ └── EurekaServerApplicationTests.class └── provider-ticket │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ ├── provider-ticket.iml │ ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── cloud │ │ │ │ └── provider │ │ │ │ ├── ProviderApplication.java │ │ │ │ ├── controller │ │ │ │ └── TickerController.java │ │ │ │ └── service │ │ │ │ ├── TicketService.java │ │ │ │ └── impl │ │ │ │ └── TicketServiceImpl.java │ │ └── resources │ │ │ └── application.yml │ └── test │ │ └── java │ │ └── com │ │ └── cloud │ │ └── provider │ │ └── ProviderApplicationTests.java │ └── target │ ├── classes │ ├── application.yml │ └── com │ │ └── cloud │ │ └── provider │ │ ├── ProviderApplication.class │ │ ├── controller │ │ └── TickerController.class │ │ └── service │ │ ├── TicketService.class │ │ └── impl │ │ └── TicketServiceImpl.class │ ├── maven-archiver │ └── pom.properties │ ├── maven-status │ └── maven-compiler-plugin │ │ ├── compile │ │ └── default-compile │ │ │ └── inputFiles.lst │ │ └── testCompile │ │ └── default-testCompile │ │ └── inputFiles.lst │ ├── provider-ticket-0.0.1-SNAPSHOT.jar.original │ ├── surefire-reports │ ├── TEST-com.atguigu.providerticket.ProviderTicketApplicationTests.xml │ ├── TEST-com.cloud.provider.ProviderApplicationTests.xml │ ├── com.atguigu.providerticket.ProviderTicketApplicationTests.txt │ └── com.cloud.provider.ProviderApplicationTests.txt │ └── test-classes │ └── com │ └── cloud │ └── provider │ └── ProviderApplicationTests.class ├── SpringBoot+SpringSecurity ├── .gitignore ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── boot │ │ │ └── security │ │ │ ├── SecurityApplication.java │ │ │ ├── config │ │ │ └── MySecurityConfig.java │ │ │ └── controller │ │ │ └── KungfuController.java │ └── resources │ │ └── templates │ │ ├── pages │ │ ├── level1 │ │ │ ├── 1.html │ │ │ ├── 2.html │ │ │ └── 3.html │ │ ├── level2 │ │ │ ├── 1.html │ │ │ ├── 2.html │ │ │ └── 3.html │ │ ├── level3 │ │ │ ├── 1.html │ │ │ ├── 2.html │ │ │ └── 3.html │ │ └── login.html │ │ └── welcome.html │ └── test │ └── java │ └── com │ └── boot │ └── security │ └── SecurityApplicationTests.java ├── SpringBoot2.0+SpringDataJPA ├── hhjpa.iml ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── jane │ │ │ ├── JpaApplication.java │ │ │ ├── config │ │ │ └── MyConfig.java │ │ │ ├── controller │ │ │ ├── AddressController.java │ │ │ └── UserController.java │ │ │ ├── dao │ │ │ ├── AddressRepository.java │ │ │ ├── CommonJpaRepositoryFactoryBean.java │ │ │ ├── CommonMethodTest.java │ │ │ ├── CommonMethodTestImpl.java │ │ │ ├── UserDao.java │ │ │ ├── UserRepository.java │ │ │ └── UserRepositoryImpl.java │ │ │ ├── model │ │ │ ├── Address.java │ │ │ └── User.java │ │ │ └── service │ │ │ ├── UserServcie.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── jane │ └── JpaApplicationTests.java ├── boot-redis ├── 6379.conf ├── 6380.conf ├── 6381.conf ├── pom.xml ├── sentinel.conf ├── sentinel26380.conf ├── sentinel26381.conf └── src │ └── main │ ├── java │ └── com │ │ └── boot │ │ └── redis │ │ ├── BootRedisApplication.java │ │ ├── config │ │ └── RedisConfig.java │ │ └── controller │ │ └── RedisController.java │ └── resources │ └── application.yml ├── elasticsearch ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── jane │ │ │ └── elasticsearch │ │ │ ├── ElasticsearchApplication.java │ │ │ ├── config │ │ │ ├── ElasticsearchConfig.java │ │ │ ├── ReactiveRepositoryConfig.java │ │ │ └── RestClientConfig.java │ │ │ ├── controller │ │ │ ├── ReactiveController.java │ │ │ └── TestController.java │ │ │ ├── model │ │ │ └── Person.java │ │ │ └── repository │ │ │ └── ReactivePersonRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── jane │ └── elasticsearch │ └── ElasticsearchApplicationTests.java ├── springboot+dubbo+zookeeper-new ├── boot-order-service-consumer │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── web │ │ │ │ └── gmall │ │ │ │ ├── BootOrderServiceConsumerApplication.java │ │ │ │ ├── config │ │ │ │ └── MyDubboConfig.java │ │ │ │ ├── controller │ │ │ │ └── OrderController.java │ │ │ │ └── service │ │ │ │ └── impl │ │ │ │ └── OrderServiceImpl.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── consumer.xml │ │ │ └── dubbo.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── web │ │ └── gmall │ │ └── BootOrderServiceConsumerApplicationTests.java ├── boot-user-service-provider-20881 │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── web │ │ │ │ └── gmall │ │ │ │ ├── BootUserServiceProvider20881Application.java │ │ │ │ ├── config │ │ │ │ └── MyDubboConfig.java │ │ │ │ └── service │ │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── web │ │ └── gmall │ │ └── BootUserServiceProvider20881ApplicationTests.java ├── boot-user-service-provider-20882 │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── web │ │ │ │ └── gmall │ │ │ │ ├── BootUserServiceProvider20882Application.java │ │ │ │ ├── config │ │ │ │ └── MyDubboConfig.java │ │ │ │ └── service │ │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── web │ │ └── gmall │ │ └── BootUserServiceProvider20882ApplicationTests.java ├── boot-user-service-provider │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── bin │ │ ├── .gitignore │ │ ├── .mvn │ │ │ └── wrapper │ │ │ │ ├── maven-wrapper.jar │ │ │ │ └── maven-wrapper.properties │ │ ├── mvnw │ │ ├── mvnw.cmd │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── resources │ │ │ └── application.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── web │ │ │ │ └── gmall │ │ │ │ ├── BootUserServiceProviderApplication.java │ │ │ │ ├── config │ │ │ │ └── MyDubboConfig.java │ │ │ │ └── service │ │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── dubbo.properties │ │ │ └── provider.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── web │ │ └── gmall │ │ └── BootUserServiceProviderApplicationTests.java ├── gmall-interface │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── web │ │ └── gmall │ │ ├── bean │ │ └── UserAddress.java │ │ └── service │ │ ├── OrderService.java │ │ ├── UserService.java │ │ └── stub │ │ └── UserServiceStub.java ├── order-service-consumer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── web │ │ │ └── gmall │ │ │ ├── MainApplication.java │ │ │ └── service │ │ │ └── impl │ │ │ └── OrderServiceImpl.java │ │ └── resources │ │ └── consumer.xml └── user-service-provider │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── web │ │ └── gmall │ │ ├── MainApplication.java │ │ └── service │ │ └── impl │ │ ├── UserServiceImpl.java │ │ └── UserServiceImpl2.java │ └── resources │ └── provider.xml └── springboot+dubbo+zookeeper ├── consumer-user ├── consumer-user.iml ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dubbo │ │ │ │ ├── consumer │ │ │ │ ├── ConsumerApplication.java │ │ │ │ └── service │ │ │ │ │ └── UserService.java │ │ │ │ └── provider │ │ │ │ ├── ProviderApplication.java │ │ │ │ └── service │ │ │ │ └── TicketService.java │ │ └── resources │ │ │ └── application.properties │ └── test │ │ └── java │ │ └── com │ │ └── dubbo │ │ └── consumer │ │ └── ConsumerApplicationTests.java └── target │ ├── classes │ ├── application.properties │ └── com │ │ └── dubbo │ │ ├── consumer │ │ ├── ConsumerApplication.class │ │ └── service │ │ │ └── UserService.class │ │ └── provider │ │ ├── ProviderApplication.class │ │ └── service │ │ └── TicketService.class │ └── test-classes │ └── com │ └── dubbo │ └── consumer │ └── ConsumerApplicationTests.class └── provider-ticket ├── mvnw ├── mvnw.cmd ├── pom.xml ├── provider-ticket.iml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── dubbo │ │ │ └── provider │ │ │ ├── ProviderApplication.java │ │ │ └── service │ │ │ ├── TicketService.java │ │ │ └── impl │ │ │ └── TicketServiceImpl.java │ └── resources │ │ └── application.properties └── test │ └── java │ └── com │ └── dubbo │ └── provider │ └── ProviderApplicationTests.java └── target ├── classes ├── application.properties └── com │ └── dubbo │ └── provider │ ├── ProviderApplication.class │ └── service │ ├── TicketService.class │ └── impl │ └── TicketServiceImpl.class └── test-classes └── com └── dubbo └── provider └── ProviderApplicationTests.class /README.md: -------------------------------------------------------------------------------- 1 | # SpringBooot 2 | SpringBoot的应用实践以及整合其他框架的一些可用demo。仓库在持续更新中。 3 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | consumer-user 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | consumer-user 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.12.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.SR3 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/src/main/java/com/cloud/consumer/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @EnableDiscoveryClient//开启发现服务功能 11 | @SpringBootApplication 12 | public class ConsumerApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ConsumerApplication.class, args); 16 | } 17 | 18 | @LoadBalanced//开启负载均衡机制 19 | @Bean 20 | public RestTemplate restTemplate(){ 21 | return new RestTemplate(); 22 | // 用来发送http请求 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/src/main/java/com/cloud/consumer/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.cloud.consumer.controller; 2 | 3 | import com.netflix.discovery.converters.Auto; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | /** 10 | * Created by Janus on 2018/7/11. 11 | */ 12 | @RestController 13 | public class UserController { 14 | 15 | @Autowired 16 | RestTemplate restTemplate; 17 | 18 | @GetMapping("/buy") 19 | public String butTicket(String name){ 20 | String s = restTemplate.getForObject("http://PROVIDER-TICKET/ticket", String.class); 21 | return name+"购买了"+s; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: consumer-user 4 | server: 5 | port: 8200 6 | 7 | eureka: 8 | instance: 9 | prefer-ip-address: true # 注册服务的时候使用服务的ip地址 10 | client: 11 | service-url: 12 | defaultZone: http://localhost:8761/eureka/ 13 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/src/test/java/com/cloud/consumer/ConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.consumer; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ConsumerApplicationTests { 11 | 12 | 13 | @Test 14 | public void contextLoads() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/target/classes/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: consumer-user 4 | server: 5 | port: 8200 6 | 7 | eureka: 8 | instance: 9 | prefer-ip-address: true # 注册服务的时候使用服务的ip地址 10 | client: 11 | service-url: 12 | defaultZone: http://localhost:8761/eureka/ 13 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/target/classes/com/cloud/consumer/ConsumerApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/consumer-user/target/classes/com/cloud/consumer/ConsumerApplication.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/target/classes/com/cloud/consumer/controller/UserController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/consumer-user/target/classes/com/cloud/consumer/controller/UserController.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/consumer-user/target/test-classes/com/cloud/consumer/ConsumerApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/consumer-user/target/test-classes/com/cloud/consumer/ConsumerApplicationTests.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/eureka-server/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | eureka-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | eureka-server 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.12.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.SR3 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka-server 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/eureka-server/src/main/java/com/cloud/eureka/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud.eureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * Created by Janus on 2018/7/11. 9 | */ 10 | @EnableEurekaServer 11 | @SpringBootApplication 12 | public class EurekaServerApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(EurekaServerApplication.class, args); 16 | } 17 | } -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | eureka: 4 | instance: 5 | hostname: eureka-server # eureka实例的主机名 6 | client: 7 | register-with-eureka: false #不把自己注册到eureka上 8 | fetch-registry: false #不从eureka上来获取服务的注册信息 9 | service-url: 10 | defaultZone: http://localhost:8761/eureka/ 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/eureka-server/src/test/java/com/cloud/eureka/EurekaServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.eureka; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EurekaServerApplicationTests { 11 | 12 | 13 | @Test 14 | public void contextLoads() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/eureka-server/target/classes/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | eureka: 4 | instance: 5 | hostname: eureka-server # eureka实例的主机名 6 | client: 7 | register-with-eureka: false #不把自己注册到eureka上 8 | fetch-registry: false #不从eureka上来获取服务的注册信息 9 | service-url: 10 | defaultZone: http://localhost:8761/eureka/ 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/eureka-server/target/classes/com/cloud/eureka/EurekaServerApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/eureka-server/target/classes/com/cloud/eureka/EurekaServerApplication.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/eureka-server/target/test-classes/com/cloud/eureka/EurekaServerApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/eureka-server/target/test-classes/com/cloud/eureka/EurekaServerApplicationTests.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | provider-ticket 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | provider-ticket 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.12.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.SR3 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/src/main/java/com/cloud/provider/ProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.cloud.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | @EnableEurekaClient 8 | public class ProviderApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(ProviderApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/src/main/java/com/cloud/provider/controller/TickerController.java: -------------------------------------------------------------------------------- 1 | package com.cloud.provider.controller; 2 | 3 | import com.cloud.provider.service.TicketService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * Created by Janus on 2018/7/11. 11 | */ 12 | @RestController 13 | public class TickerController { 14 | 15 | @Autowired 16 | TicketService ticketService; 17 | 18 | @Value("${server.port}") 19 | String port; 20 | 21 | // SpringCloud 整合微服务时是按照轻量级的HTTP进行通信 22 | @GetMapping("/ticket") 23 | public String getTicker(){ 24 | System.out.println("端口:"+port); 25 | return ticketService.getTicket(); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/src/main/java/com/cloud/provider/service/TicketService.java: -------------------------------------------------------------------------------- 1 | package com.cloud.provider.service; 2 | 3 | /** 4 | * Created by Janus on 2018/7/11. 5 | */ 6 | public interface TicketService { 7 | 8 | public String getTicket(); 9 | } 10 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/src/main/java/com/cloud/provider/service/impl/TicketServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.cloud.provider.service.impl; 2 | 3 | import com.cloud.provider.service.TicketService; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * Created by Janus on 2018/7/11. 8 | */ 9 | @Service//Spring 注解 10 | public class TicketServiceImpl implements TicketService { 11 | 12 | @Override 13 | public String getTicket() { 14 | return "《厉害了,我的国》"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8001 3 | spring: 4 | application: 5 | name: provider-ticket 6 | 7 | 8 | eureka: 9 | instance: 10 | prefer-ip-address: true # 注册服务的时候使用服务的ip地址 11 | client: 12 | service-url: 13 | defaultZone: http://localhost:8761/eureka/ 14 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/src/test/java/com/cloud/provider/ProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cloud.provider; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProviderApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/classes/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8001 3 | spring: 4 | application: 5 | name: provider-ticket 6 | 7 | 8 | eureka: 9 | instance: 10 | prefer-ip-address: true # 注册服务的时候使用服务的ip地址 11 | client: 12 | service-url: 13 | defaultZone: http://localhost:8761/eureka/ 14 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/classes/com/cloud/provider/ProviderApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/provider-ticket/target/classes/com/cloud/provider/ProviderApplication.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/classes/com/cloud/provider/controller/TickerController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/provider-ticket/target/classes/com/cloud/provider/controller/TickerController.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/classes/com/cloud/provider/service/TicketService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/provider-ticket/target/classes/com/cloud/provider/service/TicketService.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/classes/com/cloud/provider/service/impl/TicketServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/provider-ticket/target/classes/com/cloud/provider/service/impl/TicketServiceImpl.class -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/maven-archiver/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Apache Maven 2 | #Tue May 08 11:40:29 GMT+08:00 2018 3 | version=0.0.1-SNAPSHOT 4 | groupId=com.atguigu 5 | artifactId=provider-ticket 6 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | D:\BaiduYunDownload\尚硅谷SpringBoot整合篇\课件\代码\springboot-06-springcloud\provider-ticket\src\main\java\com\cloud\provider\ProviderApplication.java 2 | D:\BaiduYunDownload\尚硅谷SpringBoot整合篇\课件\代码\springboot-06-springcloud\provider-ticket\src\main\java\com\cloud\provider\controller\TickerController.java 3 | D:\BaiduYunDownload\尚硅谷SpringBoot整合篇\课件\代码\springboot-06-springcloud\provider-ticket\src\main\java\com\cloud\provider\service\impl\TicketServiceImpl.java 4 | D:\BaiduYunDownload\尚硅谷SpringBoot整合篇\课件\代码\springboot-06-springcloud\provider-ticket\src\main\java\com\cloud\provider\service\TicketService.java 5 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | D:\BaiduYunDownload\尚硅谷SpringBoot整合篇\课件\代码\springboot-06-springcloud\provider-ticket\src\test\java\com\cloud\provider\ProviderApplicationTests.java 2 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/provider-ticket-0.0.1-SNAPSHOT.jar.original: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/provider-ticket/target/provider-ticket-0.0.1-SNAPSHOT.jar.original -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/surefire-reports/TEST-com.cloud.provider.ProviderApplicationTests.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/surefire-reports/com.atguigu.providerticket.ProviderTicketApplicationTests.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | Test set: com.atguigu.providerticket.ProviderTicketApplicationTests 3 | ------------------------------------------------------------------------------- 4 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.617 sec - in com.atguigu.providerticket.ProviderTicketApplicationTests 5 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/surefire-reports/com.cloud.provider.ProviderApplicationTests.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | Test set: com.cloud.provider.ProviderApplicationTests 3 | ------------------------------------------------------------------------------- 4 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.99 sec - in com.cloud.provider.ProviderApplicationTests 5 | -------------------------------------------------------------------------------- /SpringBoot+SpringCloud/provider-ticket/target/test-classes/com/cloud/provider/ProviderApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/SpringBoot+SpringCloud/provider-ticket/target/test-classes/com/cloud/provider/ProviderApplicationTests.class -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.boot 7 | security 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | security 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.14.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 3.0.9.RELEASE 26 | 2.3.0 27 | 3.0.2.RELEASE 28 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-security 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-web 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-thymeleaf 42 | 43 | 44 | org.thymeleaf.extras 45 | thymeleaf-extras-springsecurity4 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-test 57 | test 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-maven-plugin 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/java/com/boot/security/SecurityApplication.java: -------------------------------------------------------------------------------- 1 | package com.boot.security; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 6 | 7 | @SpringBootApplication 8 | public class SecurityApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(SecurityApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/java/com/boot/security/config/MySecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.boot.security.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * Created by Janus on 2018/7/10. 13 | */ 14 | @EnableWebSecurity 15 | public class MySecurityConfig extends WebSecurityConfigurerAdapter { 16 | 17 | // @Autowired 18 | // private DataSource dataSource; 19 | @Override 20 | protected void configure(HttpSecurity http) throws Exception { 21 | // 定制请求的授权规则 22 | http.authorizeRequests() 23 | .antMatchers("/css/**", "/").permitAll() 24 | .antMatchers("/level1/**").hasRole("VIP1") 25 | .antMatchers("/level2/**").hasRole("VIP2") 26 | .antMatchers("/level3/**").hasRole("VIP3"); 27 | // 开启自动配置的登录功能 28 | http.formLogin().usernameParameter("name").passwordParameter("pwd").loginPage("/userlogin"); 29 | 30 | // 开启自动配置的注销功能,默认重定向到/logout?success,修改为"/" 31 | http.logout().logoutSuccessUrl("/"); 32 | 33 | //开启自动配置的Remember me 34 | http.rememberMe().rememberMeParameter("remember"); 35 | } 36 | 37 | @Override 38 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 39 | auth.inMemoryAuthentication() 40 | .withUser("zhangsan").password("123456").roles("VIP1","VIP2") 41 | .and() 42 | .withUser("lisi").password("123456").roles("VIP3","VIP2") 43 | .and() 44 | .withUser("wangwu").password("123456").roles("VIP3","VIP1"); 45 | // auth.jdbcAuthentication().dataSource(dataSource) 46 | // .usersByUsernameQuery("select username,password, enabled from users where username = ?") 47 | // .authoritiesByUsernameQuery("select username, role from user_roles where username = ?"); 48 | } 49 | 50 | 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/java/com/boot/security/controller/KungfuController.java: -------------------------------------------------------------------------------- 1 | package com.boot.security.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | 7 | @Controller 8 | public class KungfuController { 9 | 10 | private final String PREFIX = "pages/"; 11 | /** 12 | * 欢迎页 13 | * @return 14 | */ 15 | @GetMapping("/") 16 | public String index() { 17 | System.out.println("进入访问页面!"); 18 | return "welcome"; 19 | } 20 | 21 | /** 22 | * 登陆页 23 | * @return 24 | */ 25 | @GetMapping("/userlogin") 26 | public String loginPage() { 27 | return PREFIX+"login"; 28 | } 29 | 30 | 31 | /** 32 | * level1页面映射 33 | * @param path 34 | * @return 35 | */ 36 | @GetMapping("/level1/{path}") 37 | public String level1(@PathVariable("path")String path) { 38 | return PREFIX+"level1/"+path; 39 | } 40 | 41 | /** 42 | * level2页面映射 43 | * @param path 44 | * @return 45 | */ 46 | @GetMapping("/level2/{path}") 47 | public String level2(@PathVariable("path")String path) { 48 | return PREFIX+"level2/"+path; 49 | } 50 | 51 | /** 52 | * level3页面映射 53 | * @param path 54 | * @return 55 | */ 56 | @GetMapping("/level3/{path}") 57 | public String level3(@PathVariable("path")String path) { 58 | return PREFIX+"level3/"+path; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level1/1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

罗汉拳

10 |

罗汉拳站当央,打起来不要慌

11 | 12 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level1/2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

武当长拳

10 |

长一点在长一点

11 | 12 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level1/3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

全真剑法

10 |

全都是真的

11 | 12 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level2/1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

太极拳

10 |

11 | 一个西瓜圆又圆 劈它一刀成两半 你一半来 给你你不要 给他他不收 那就不给 把两人撵走 他们不走你走 走啦,一挥手,伤自尊 12 | 不买西瓜别缠我,缓慢纠缠様 两人缠我赖皮,手慢动作左右挥动 看我厉害,转头缓步拍苍蝇状 拍死了,手抱西瓜状+奥特曼十字手+广播操准备运动的站立 13 |

14 | 15 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level2/2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

七伤拳

10 |

练这拳的人全都死了

11 | 12 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level2/3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

梯云纵

10 |

踩自己的脚往上跳

11 | 12 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level3/1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

葵花宝典

10 |

欲练神功,挥刀自宫

11 | 12 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level3/2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

龟派气功

10 |

龟-派-气-功-波

11 | 12 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/level3/3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 返回 9 |

独孤九剑

10 |

欲练此剑,必先犯贱

11 | 12 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/pages/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 |

欢迎登陆武林秘籍管理系统

9 |
10 |
11 |
12 | 用户名:
13 | 密   码:
14 | Remember-me
15 | 16 |
17 |
18 | 19 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/main/resources/templates/welcome.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |

欢迎光临武林秘籍管理系统

10 | 11 |
12 |

游客您好,如果想查看武林秘籍 请登录

13 |
14 | 15 |
16 |

,您好,您的角色有:

17 |
18 | 19 |
20 |
21 | 22 |
23 | 24 |
25 |

普通武功秘籍

26 | 31 |
32 |
33 |

高级武功秘籍

34 | 39 |
40 |
41 |

绝世武功秘籍

42 | 47 |
48 | 49 | -------------------------------------------------------------------------------- /SpringBoot+SpringSecurity/src/test/java/com/boot/security/SecurityApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.boot.security; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SecurityApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jane 7 | jpa 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | jpa 12 | Demo project for Spring Boot 13 | 14 | 15 | 16 | com.jane 17 | hh-parent 18 | 1.0-SNAPSHOT 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | mysql 39 | mysql-connector-java 40 | runtime 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | com.alibaba 51 | druid 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/JpaApplication.java: -------------------------------------------------------------------------------- 1 | package com.jane; 2 | 3 | import com.jane.dao.CommonJpaRepositoryFactoryBean; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.domain.EntityScan; 7 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 8 | 9 | @SpringBootApplication 10 | @EntityScan(basePackages={"com.jane.model"}) 11 | @EnableJpaRepositories(basePackages = {"com.jane.dao"},repositoryFactoryBeanClass = CommonJpaRepositoryFactoryBean.class) 12 | public class JpaApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(JpaApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/config/MyConfig.java: -------------------------------------------------------------------------------- 1 | package com.jane.config; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.fasterxml.jackson.databind.SerializationFeature; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * Created by Janus on 2018/9/8. 11 | */ 12 | @Configuration 13 | public class MyConfig { 14 | 15 | @Bean 16 | public ObjectMapper objectMapper() { 17 | 18 | return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/controller/AddressController.java: -------------------------------------------------------------------------------- 1 | package com.jane.controller; 2 | 3 | import com.jane.dao.AddressRepository; 4 | import com.jane.model.Address; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * Created by Janus on 2018/9/10. 11 | */ 12 | @RestController 13 | public class AddressController { 14 | 15 | @Autowired 16 | AddressRepository addressRepository; 17 | 18 | @GetMapping("/test17") 19 | public Address test17(){ 20 | Address address = addressRepository.method(); 21 | return address; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/dao/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package com.jane.dao; 2 | 3 | import com.jane.model.Address; 4 | 5 | public interface AddressRepository extends CommonMethodTest{ 6 | 7 | } 8 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/dao/CommonJpaRepositoryFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.jane.dao; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.EntityManager; 6 | 7 | import org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation; 8 | import org.springframework.data.jpa.repository.support.JpaRepositoryFactory; 9 | import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean; 10 | import org.springframework.data.repository.Repository; 11 | import org.springframework.data.repository.core.RepositoryMetadata; 12 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 13 | 14 | public class CommonJpaRepositoryFactoryBean, S, ID extends Serializable> 15 | extends JpaRepositoryFactoryBean { 16 | 17 | public CommonJpaRepositoryFactoryBean(Class repositoryInterface) { 18 | super(repositoryInterface); 19 | } 20 | 21 | protected RepositoryFactorySupport createRepositoryFactory( 22 | EntityManager entityManager) { 23 | return new CommonRepositoryFactory(entityManager); 24 | } 25 | 26 | private static class CommonRepositoryFactory 27 | extends JpaRepositoryFactory { 28 | 29 | private EntityManager entityManager; 30 | 31 | public CommonRepositoryFactory(EntityManager entityManager) { 32 | super(entityManager); 33 | this.entityManager = entityManager; 34 | } 35 | 36 | protected Object getTargetRepository(JpaMetamodelEntityInformation information) { 37 | 38 | return new CommonMethodTestImpl(information,entityManager); 39 | } 40 | // protected Object getTargetRepository(RepositoryMetadata metadata) { 41 | // 42 | // return new CommonMethodTestImpl( 43 | // (Class) metadata.getDomainType(), entityManager); 44 | // } 45 | 46 | protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { 47 | return CommonMethodTestImpl.class; 48 | } 49 | // protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { 50 | // return CommonMethodTest.class; 51 | // } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/dao/CommonMethodTest.java: -------------------------------------------------------------------------------- 1 | package com.jane.dao; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.repository.NoRepositoryBean; 7 | 8 | import javax.persistence.EntityManager; 9 | import com.jane.model.Address; 10 | 11 | @NoRepositoryBean 12 | public interface CommonMethodTest extends JpaRepository{ 13 | 14 | Address method(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/dao/CommonMethodTestImpl.java: -------------------------------------------------------------------------------- 1 | package com.jane.dao; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.EntityManager; 6 | 7 | import com.jane.model.*; 8 | import org.springframework.data.jpa.repository.support.JpaEntityInformation; 9 | import org.springframework.data.jpa.repository.support.SimpleJpaRepository; 10 | import org.springframework.data.repository.NoRepositoryBean; 11 | 12 | @NoRepositoryBean 13 | public class CommonMethodTestImpl 14 | extends SimpleJpaRepository implements CommonMethodTest { 15 | 16 | private EntityManager entityManager; 17 | 18 | public CommonMethodTestImpl(Class domainClass, EntityManager em) { 19 | super(domainClass, em); 20 | } 21 | 22 | public CommonMethodTestImpl(JpaEntityInformation entityInformation, EntityManager em) { 23 | 24 | super(entityInformation, em); 25 | 26 | this.entityManager = em; 27 | } 28 | 29 | @Override 30 | public Address method() { 31 | Address address = entityManager.find(Address.class, 1); 32 | System.out.println("...BASE METHOD TEST..."); 33 | return address; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.jane.dao; 2 | 3 | import com.jane.model.User; 4 | 5 | /** 6 | * Created by Janus on 2018/9/10. 7 | */ 8 | public interface UserDao { 9 | 10 | User getUserById(Integer id); 11 | } 12 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/dao/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.jane.dao; 2 | 3 | /** 4 | * Created by Janus on 2018/9/8. 5 | */ 6 | 7 | import com.jane.model.User; 8 | import org.springframework.data.domain.Page; 9 | import org.springframework.data.domain.Pageable; 10 | import org.springframework.data.jpa.domain.Specification; 11 | import org.springframework.data.jpa.repository.JpaRepository; 12 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 13 | import org.springframework.data.jpa.repository.Modifying; 14 | import org.springframework.data.jpa.repository.Query; 15 | import org.springframework.data.repository.query.Param; 16 | import org.springframework.lang.Nullable; 17 | 18 | import java.util.List; 19 | 20 | public interface UserRepository 21 | extends UserDao,JpaRepository,JpaSpecificationExecutor { 22 | 23 | /** 24 | * 符合查询方法规范的几个方法 25 | * @param email 26 | * @return 27 | */ 28 | List findByEmail(String email); 29 | 30 | //where lastName like ?% and id getByLastNameStartingWithAndIdLessThan(String lastName,Integer id); 32 | 33 | //WHERE User.addressId > ? 34 | List getByAddressIdGreaterThan(Integer id); 35 | 36 | //WHERE a.id > ? 37 | List getByAddress_IdGreaterThan(Integer id); 38 | 39 | /** 40 | * @Query注解,使用JPQL查询语言 41 | * @return 42 | */ 43 | @Query("select u from User u where u.id=(select max(u2.id) from User u2)") 44 | User getMaxIdPerson(); 45 | 46 | /** 47 | * 索引参数 48 | * @param lastName 49 | * @param email 50 | * @return 51 | */ 52 | @Query("select u from User u where u.lastName=?1 and u.email=?2") 53 | User testQueryAnnotationParams1(String lastName,String email); 54 | 55 | /** 56 | * 命名参数 57 | * @param lastName 58 | * @param email 59 | * @return 60 | */ 61 | @Query("select u from User u where u.lastName=:lastName and u.email=:email") 62 | User testQueryAnnotationParams2(@Param("lastName") String lastName, @Param("email") String email); 63 | 64 | /** 65 | * 模糊查询 like关键字 66 | * @param lastName 67 | * @return 68 | */ 69 | @Query("select u from User u where u.lastName LIKE ?1%") 70 | List findBylastName (String lastName ); 71 | 72 | /** 73 | * 本地查询,执行原生SQL 74 | * @return 75 | */ 76 | 77 | @Query(nativeQuery = true,value = "select count(1) from tb_user") 78 | long getTotalCount(); 79 | 80 | /** 81 | * @Modifying +@Transactional 实现JPQLupdate or delete 82 | * @param id 83 | * @param email 84 | * @return 85 | */ 86 | @Modifying 87 | @Query("update User u set u.email = :email where u.id = :id") 88 | int updateEmailById(@Param("id") Integer id,@Param("email") String email); 89 | 90 | /** 91 | * 带查询条件的分页 92 | * @param spec 93 | * @param pageable 94 | * @return 95 | */ 96 | @Override 97 | Page findAll(@Nullable Specification spec, Pageable pageable); 98 | } 99 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/dao/UserRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.jane.dao; 2 | 3 | import com.jane.model.User; 4 | 5 | import javax.jws.soap.SOAPBinding; 6 | import javax.persistence.EntityManager; 7 | import javax.persistence.PersistenceContext; 8 | 9 | /** 10 | * Created by Janus on 2018/9/10. 11 | */ 12 | public class UserRepositoryImpl implements UserDao { 13 | 14 | @PersistenceContext 15 | private EntityManager entityManager; 16 | 17 | public User getUserById(Integer id) { 18 | User user = entityManager.find(User.class, id); 19 | System.out.println("UserRepositoryImpl.getUserById()"); 20 | return user; 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/model/Address.java: -------------------------------------------------------------------------------- 1 | package com.jane.model; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | 6 | @Table(name="tb_address") 7 | @Entity 8 | public class Address implements Serializable { 9 | 10 | private Integer id; 11 | private String province; 12 | private String city; 13 | 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.IDENTITY) 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | 24 | public String getProvince() { 25 | return province; 26 | } 27 | 28 | public void setProvince(String province) { 29 | this.province = province; 30 | } 31 | 32 | public String getCity() { 33 | return city; 34 | } 35 | 36 | public void setCity(String city) { 37 | this.city = city; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "Address{" + 43 | "id=" + id + 44 | ", province='" + province + '\'' + 45 | ", city='" + city + '\'' + 46 | '}'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/model/User.java: -------------------------------------------------------------------------------- 1 | package com.jane.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | import javax.persistence.*; 6 | import java.io.Serializable; 7 | 8 | /** 9 | * Created by Janus on 2018/9/8. 10 | */ 11 | //@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"}) 12 | @Entity //告诉JPA这是一个实体类(和数据表映射的类) 13 | @Table(name = "tb_user") //@Table来指定和哪个数据表对应;如果省略默认表名就是user; 14 | public class User implements Serializable{ 15 | 16 | @Id //这是一个主键 17 | @GeneratedValue(strategy = GenerationType.IDENTITY)//自增主键 18 | private Integer id; 19 | 20 | @Column(name = "last_name",length = 50) //这是和数据表对应的一个列 21 | private String lastName; 22 | 23 | @Column //省略默认列名就是属性名 24 | private String email; 25 | 26 | @ManyToOne 27 | @JoinColumn(name = "address_id") 28 | private Address address; 29 | 30 | @Column(name = "add_id") 31 | private Integer addressId; 32 | 33 | 34 | public Integer getAddressId() { 35 | return addressId; 36 | } 37 | 38 | public void setAddressId(Integer addressId) { 39 | this.addressId = addressId; 40 | } 41 | 42 | public Integer getId() { 43 | return id; 44 | } 45 | 46 | public void setId(Integer id) { 47 | this.id = id; 48 | } 49 | 50 | public String getLastName() { 51 | return lastName; 52 | } 53 | 54 | public void setLastName(String lastName) { 55 | this.lastName = lastName; 56 | } 57 | 58 | public String getEmail() { 59 | return email; 60 | } 61 | 62 | public void setEmail(String email) { 63 | this.email = email; 64 | } 65 | 66 | public Address getAddress() { 67 | return address; 68 | } 69 | 70 | public void setAddress(Address address) { 71 | this.address = address; 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "User{" + 77 | "id=" + id + 78 | ", lastName='" + lastName + '\'' + 79 | ", email='" + email + '\'' + 80 | ", address=" + address + 81 | '}'; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/service/UserServcie.java: -------------------------------------------------------------------------------- 1 | package com.jane.service; 2 | 3 | import org.springframework.data.repository.query.Param; 4 | 5 | import javax.transaction.Transactional; 6 | 7 | /** 8 | * Created by Janus on 2018/9/10. 9 | */ 10 | public interface UserServcie { 11 | 12 | // @Transactional 13 | int updateEmailById(Integer id,String email); 14 | } 15 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/java/com/jane/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jane.service.impl; 2 | 3 | import com.jane.dao.UserRepository; 4 | import com.jane.service.UserServcie; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.transaction.Transactional; 9 | 10 | /** 11 | * Created by Janus on 2018/9/10. 12 | */ 13 | @Service 14 | public class UserServiceImpl implements UserServcie{ 15 | 16 | @Autowired 17 | UserRepository userRepository; 18 | 19 | @Transactional 20 | public int updateEmailById(Integer id, String email) { 21 | System.out.println("进入Service方法。。。"); 22 | int i = userRepository.updateEmailById(id, email); 23 | return i; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | spring: 5 | datasource: 6 | url: jdbc:mysql://localhost:3306/test 7 | username: root 8 | password: 123456 9 | driver-class-name: com.mysql.jdbc.Driver 10 | type: com.alibaba.druid.pool.DruidDataSource 11 | initialSize: 50 12 | maxActive: 200 13 | maxWait: 60000 14 | minIdle: 20 15 | timeBetweenEvictionRunsMillis: 60000 16 | minEvictableIdleTimeMillis: 300000 17 | validationQuery: SELECT 1 FROM DUAL 18 | testWhileIdle: true 19 | testOnBorrow: true 20 | testOnReturn: false 21 | poolPreparedStatements: true 22 | # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 23 | filters: stat,wall,log4j 24 | maxPoolPreparedStatementPerConnectionSize: 20 25 | useGlobalDataSourceStat: true 26 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 27 | jpa: 28 | database: mysql 29 | hibernate: 30 | ddl-auto: update 31 | show-sql: true -------------------------------------------------------------------------------- /SpringBoot2.0+SpringDataJPA/src/test/java/com/jane/JpaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.jane; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class JpaApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /boot-redis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.1.RELEASE 9 | 10 | 11 | com.boot.redis 12 | boot-redis 13 | 0.0.1-SNAPSHOT 14 | boot-redis 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-redis 25 | 26 | 27 | redis.clients 28 | jedis 29 | 30 | 31 | io.lettuce 32 | lettuce-core 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-web 39 | 40 | 41 | redis.clients 42 | jedis 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-test 48 | test 49 | 50 | 51 | org.apache.commons 52 | commons-pool2 53 | 2.5.0 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /boot-redis/sentinel.conf: -------------------------------------------------------------------------------- 1 | port 26379 2 | sentinel monitor mymaster 192.168.2.110 6379 2 3 | sentinel auth-pass mymaster admin 4 | sentinel down-after-milliseconds mymaster 15000 5 | sentinel parallel-syncs mymaster 1 6 | sentinel failover-timeout mymaster 80000 7 | bind 192.168.2.110 8 | protected-mode yes 9 | -------------------------------------------------------------------------------- /boot-redis/sentinel26380.conf: -------------------------------------------------------------------------------- 1 | port 26380 2 | sentinel monitor mymaster 192.168.2.110 6379 2 3 | sentinel auth-pass mymaster admin 4 | sentinel down-after-milliseconds mymaster 15000 5 | sentinel parallel-syncs mymaster 1 6 | sentinel failover-timeout mymaster 80000 7 | bind 192.168.2.110 8 | protected-mode yes 9 | -------------------------------------------------------------------------------- /boot-redis/sentinel26381.conf: -------------------------------------------------------------------------------- 1 | port 26381 2 | sentinel monitor mymaster 192.168.2.110 6379 2 3 | sentinel auth-pass mymaster admin 4 | sentinel down-after-milliseconds mymaster 15000 5 | sentinel parallel-syncs mymaster 1 6 | sentinel failover-timeout mymaster 80000 7 | bind 192.168.2.110 8 | protected-mode yes -------------------------------------------------------------------------------- /boot-redis/src/main/java/com/boot/redis/BootRedisApplication.java: -------------------------------------------------------------------------------- 1 | package com.boot.redis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootRedisApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootRedisApplication.class, args); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /boot-redis/src/main/java/com/boot/redis/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.boot.redis.config; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.data.redis.connection.RedisNode; 11 | import org.springframework.data.redis.connection.RedisSentinelConfiguration; 12 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; 13 | import org.springframework.data.redis.core.RedisTemplate; 14 | import org.springframework.data.redis.core.StringRedisTemplate; 15 | import redis.clients.jedis.JedisPoolConfig; 16 | 17 | import java.util.HashSet; 18 | import java.util.List; 19 | import java.util.Set; 20 | 21 | /** 22 | * Created by Janus on 2019/1/11. 23 | */ 24 | @Configuration 25 | @EnableAutoConfiguration 26 | public class RedisConfig { 27 | private static Logger logger = LoggerFactory.getLogger(RedisConfig.class); 28 | 29 | @Value("#{'${spring.redis.sentinel.nodes}'.split(',')}") 30 | private List nodes; 31 | 32 | @Bean 33 | @ConfigurationProperties(prefix="spring.redis") 34 | public JedisPoolConfig getRedisConfig(){ 35 | JedisPoolConfig config = new JedisPoolConfig(); 36 | return config; 37 | } 38 | @Bean 39 | public RedisSentinelConfiguration sentinelConfiguration(){ 40 | RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration(); 41 | //配置matser的名称 42 | redisSentinelConfiguration.master("mymaster"); 43 | //配置redis的哨兵sentinel 44 | Set redisNodeSet = new HashSet<>(); 45 | nodes.forEach(x->{ 46 | redisNodeSet.add(new RedisNode(x.split(":")[0],Integer.parseInt(x.split(":")[1]))); 47 | }); 48 | logger.info("redisNodeSet -->"+redisNodeSet); 49 | redisSentinelConfiguration.setSentinels(redisNodeSet); 50 | return redisSentinelConfiguration; 51 | } 52 | 53 | @Bean 54 | public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig,RedisSentinelConfiguration sentinelConfig) { 55 | JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(sentinelConfig,jedisPoolConfig); 56 | return jedisConnectionFactory; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /boot-redis/src/main/java/com/boot/redis/controller/RedisController.java: -------------------------------------------------------------------------------- 1 | package com.boot.redis.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.redis.core.StringRedisTemplate; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.ResponseBody; 8 | 9 | import java.time.LocalDate; 10 | import java.time.LocalDateTime; 11 | import java.util.Random; 12 | 13 | /** 14 | * Created by Janus on 2019/1/11. 15 | */ 16 | @Controller 17 | public class RedisController { 18 | 19 | @Autowired 20 | StringRedisTemplate redisTemplate; 21 | 22 | @ResponseBody 23 | @RequestMapping("/test") 24 | public String test(){ 25 | System.out.println("进入test方法 "+ LocalDateTime.now()); 26 | int value= (int)(Math.random()*100); 27 | String v2="v"+value; 28 | redisTemplate.opsForValue().set("name",v2); 29 | String name = redisTemplate.opsForValue().get("name"); 30 | return name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /boot-redis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | redis: 3 | password: admin 4 | jedis: 5 | pool: 6 | #最大连接数 7 | max-active: 1024 8 | #最大阻塞等待时间(负数表示没限制) 9 | max-wait: 20000 10 | #最大空闲 11 | max-idle: 200 12 | #最小空闲 13 | min-idle: 10 14 | sentinel: 15 | master: mymaster 16 | nodes: 192.168.2.110:26379,192.168.2.110:26380,192.168.2.110:26381 17 | # - 192.168.2.110:26379 18 | # - 192.168.2.110:26380 19 | # - 192.168.2.110:26381 20 | server: 21 | port: 8088 22 | -------------------------------------------------------------------------------- /elasticsearch/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.0.RELEASE 9 | 10 | com.jane 11 | elasticsearch 12 | 0.0.1-SNAPSHOT 13 | elasticsearch 14 | Demo project for Spring Boot 15 | 16 | 17 | 1.8 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-web 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-webflux 29 | 30 | 31 | org.springframework.data 32 | spring-data-elasticsearch 33 | 3.2.3.RELEASE 34 | 35 | 36 | 37 | io.projectreactor 38 | reactor-core 39 | 3.3.1.RELEASE 40 | 41 | 42 | 43 | io.projectreactor.netty 44 | reactor-netty 45 | 0.9.2.RELEASE 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.springframework.boot 79 | spring-boot-starter-test 80 | test 81 | 82 | 83 | org.junit.vintage 84 | junit-vintage-engine 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | org.springframework.boot 94 | spring-boot-maven-plugin 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /elasticsearch/src/main/java/com/jane/elasticsearch/ElasticsearchApplication.java: -------------------------------------------------------------------------------- 1 | package com.jane.elasticsearch; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ElasticsearchApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ElasticsearchApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /elasticsearch/src/main/java/com/jane/elasticsearch/config/ElasticsearchConfig.java: -------------------------------------------------------------------------------- 1 | package com.jane.elasticsearch.config; 2 | 3 | import org.elasticsearch.client.RestHighLevelClient; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.data.elasticsearch.client.ClientConfiguration; 7 | import org.springframework.data.elasticsearch.client.RestClients; 8 | 9 | /** 10 | * Created by jianggc at 2019/12/24. 11 | */ 12 | //@Configuration 13 | public class ElasticsearchConfig { 14 | // @Bean 15 | RestHighLevelClient client() { 16 | 17 | ClientConfiguration clientConfiguration = ClientConfiguration.builder() 18 | .connectedTo("192.168.18.128:9200") 19 | // .connectedTo("192.168.18.128:9300", "localhost:9301") 20 | .build(); 21 | RestHighLevelClient restHighLevelClient = RestClients.create(clientConfiguration).rest(); 22 | System.out.println(restHighLevelClient); 23 | 24 | return restHighLevelClient; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /elasticsearch/src/main/java/com/jane/elasticsearch/config/ReactiveRepositoryConfig.java: -------------------------------------------------------------------------------- 1 | package com.jane.elasticsearch.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.data.elasticsearch.client.ClientConfiguration; 5 | import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient; 6 | import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients; 7 | import org.springframework.data.elasticsearch.config.AbstractReactiveElasticsearchConfiguration; 8 | import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories; 9 | 10 | /** 11 | * Created by jianggc at 2019/12/27. 12 | */ 13 | @Configuration 14 | @EnableReactiveElasticsearchRepositories 15 | public class ReactiveRepositoryConfig extends AbstractReactiveElasticsearchConfiguration { 16 | 17 | @Override 18 | public ReactiveElasticsearchClient reactiveElasticsearchClient() { 19 | ClientConfiguration clientConfiguration = ClientConfiguration.builder() 20 | .connectedTo("192.168.18.128:9200") 21 | .withSocketTimeout(60000) 22 | .withConnectTimeout(60000) 23 | .build(); 24 | ReactiveElasticsearchClient reactiveElasticsearchClient = ReactiveRestClients.create(clientConfiguration); 25 | System.out.println("reactiveElasticsearchClient is created:"+reactiveElasticsearchClient); 26 | return reactiveElasticsearchClient; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /elasticsearch/src/main/java/com/jane/elasticsearch/config/RestClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.jane.elasticsearch.config; 2 | 3 | import org.elasticsearch.client.RestHighLevelClient; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.convert.support.DefaultConversionService; 7 | import org.springframework.data.elasticsearch.client.ClientConfiguration; 8 | import org.springframework.data.elasticsearch.client.RestClients; 9 | import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; 10 | import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper; 11 | import org.springframework.data.elasticsearch.core.EntityMapper; 12 | 13 | /** 14 | * Created by jianggc at 2019/12/25. 15 | */ 16 | //@Configuration 17 | public class RestClientConfig extends AbstractElasticsearchConfiguration { 18 | @Override 19 | public RestHighLevelClient elasticsearchClient() { 20 | ClientConfiguration clientConfiguration = ClientConfiguration.builder() 21 | .connectedTo("192.168.18.128:9200") 22 | .withSocketTimeout(60000) 23 | .withConnectTimeout(60000) 24 | .build(); 25 | RestHighLevelClient restHighLevelClient = RestClients.create(clientConfiguration).rest(); 26 | System.out.println("RestClientConfig-elasticsearchClient:"+restHighLevelClient); 27 | return restHighLevelClient; 28 | } 29 | 30 | // use the ElasticsearchEntityMapper 31 | @Bean 32 | @Override 33 | public EntityMapper entityMapper() { 34 | ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(elasticsearchMappingContext(), 35 | new DefaultConversionService()); 36 | entityMapper.setConversions(elasticsearchCustomConversions()); 37 | 38 | return entityMapper; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /elasticsearch/src/main/java/com/jane/elasticsearch/controller/ReactiveController.java: -------------------------------------------------------------------------------- 1 | package com.jane.elasticsearch.controller; 2 | 3 | import com.jane.elasticsearch.model.Person; 4 | import com.jane.elasticsearch.repository.ReactivePersonRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Sort; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | import org.springframework.web.bind.annotation.RestController; 11 | import reactor.core.publisher.Flux; 12 | import reactor.core.publisher.Mono; 13 | 14 | import java.util.List; 15 | 16 | import static org.springframework.data.domain.Sort.Direction.ASC; 17 | 18 | /** 19 | * Created by jianggc at 2019/12/27. 20 | */ 21 | @RestController 22 | public class ReactiveController { 23 | 24 | @Autowired 25 | ReactivePersonRepository repository; 26 | 27 | @RequestMapping("/testReactive") 28 | public String testReactive() { 29 | Flux persons = repository.findAll(); 30 | System.out.println(persons.blockFirst()); 31 | Mono> listMono = persons.collectList(); 32 | System.out.println("listMono:"+ listMono); 33 | List personList = listMono.block(); 34 | System.out.println("personList:"+personList); 35 | return persons.toString(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /elasticsearch/src/main/java/com/jane/elasticsearch/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.jane.elasticsearch.controller; 2 | 3 | import com.jane.elasticsearch.model.Person; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.elasticsearch.core.ElasticsearchOperations; 6 | import org.springframework.data.elasticsearch.core.query.GetQuery; 7 | import org.springframework.data.elasticsearch.core.query.IndexQuery; 8 | import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | /** 12 | * Created by jianggc at 2019/12/25. 13 | */ 14 | //@RestController 15 | public class TestController { 16 | 17 | @Autowired 18 | private ElasticsearchOperations elasticsearchOperations; 19 | 20 | // public TestController(ElasticsearchOperations elasticsearchOperations) { 21 | // this.elasticsearchOperations = elasticsearchOperations; 22 | // } 23 | 24 | @PostMapping("/person") 25 | public String save(@RequestBody Person person) { 26 | System.out.println("elasticsearchOperations:"+elasticsearchOperations); 27 | IndexQuery indexQuery = new IndexQueryBuilder() 28 | .withId(person.getId().toString()) 29 | .withObject(person) 30 | .build(); 31 | String documentId = elasticsearchOperations.index(indexQuery); 32 | return documentId; 33 | } 34 | 35 | @GetMapping("/person/{id}") 36 | public Person findById(@PathVariable("id") String id) { 37 | Person person = elasticsearchOperations 38 | .queryForObject(GetQuery.getById(id.toString()), Person.class); 39 | return person; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /elasticsearch/src/main/java/com/jane/elasticsearch/model/Person.java: -------------------------------------------------------------------------------- 1 | package com.jane.elasticsearch.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.elasticsearch.annotations.Document; 5 | import org.springframework.data.elasticsearch.annotations.Field; 6 | 7 | /** 8 | * Created by jianggc at 2019/12/25. 9 | */ 10 | @Document(indexName = "person",type = "person") 11 | public class Person { 12 | 13 | @Id 14 | private String id; 15 | private String firstname; 16 | private String lastname; 17 | 18 | public String getId() { 19 | return id; 20 | } 21 | 22 | public void setId(String id) { 23 | this.id = id; 24 | } 25 | 26 | public String getFirstname() { 27 | return firstname; 28 | } 29 | 30 | public void setFirstname(String firstname) { 31 | this.firstname = firstname; 32 | } 33 | 34 | public String getLastname() { 35 | return lastname; 36 | } 37 | 38 | public void setLastname(String lastname) { 39 | this.lastname = lastname; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Person{" + 45 | "id='" + id + '\'' + 46 | ", firstname='" + firstname + '\'' + 47 | ", lastname='" + lastname + '\'' + 48 | '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /elasticsearch/src/main/java/com/jane/elasticsearch/repository/ReactivePersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.jane.elasticsearch.repository; 2 | 3 | import com.jane.elasticsearch.model.Person; 4 | import org.reactivestreams.Publisher; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.domain.Sort; 7 | import org.springframework.data.elasticsearch.annotations.Query; 8 | import org.springframework.data.repository.reactive.ReactiveSortingRepository; 9 | import reactor.core.publisher.Flux; 10 | import reactor.core.publisher.Mono; 11 | 12 | /** 13 | * Created by jianggc at 2019/12/27. 14 | */ 15 | public interface ReactivePersonRepository extends ReactiveSortingRepository { 16 | 17 | Flux findByFirstname(String firstname); 18 | 19 | Flux findByFirstname(Publisher firstname); 20 | 21 | Flux findByFirstnameOrderByLastname(String firstname); 22 | 23 | Flux findByFirstname(String firstname, Sort sort); 24 | 25 | Flux findByFirstname(String firstname, Pageable page); 26 | 27 | Mono findByFirstnameAndLastname(String firstname, String lastname); 28 | 29 | Mono findFirstByLastname(String lastname); 30 | 31 | @Query("{ \"bool\" : { \"must\" : { \"term\" : { \"lastname\" : \"?0\" } } } }") 32 | Flux findByLastname(String lastname); 33 | 34 | Mono countByFirstname(String firstname); 35 | 36 | Mono existsByFirstname(String firstname); 37 | 38 | Mono deleteByFirstname(String firstname); 39 | } 40 | -------------------------------------------------------------------------------- /elasticsearch/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper-new/boot-order-service-consumer/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jane.dubbo 7 | boot-user-service-provider 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | boot-order-service-consumer 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | com.jane.dubbo 40 | gmall-interface 41 | 0.0.1-SNAPSHOT 42 | 43 | 44 | com.alibaba.boot 45 | dubbo-spring-boot-starter 46 | 0.2.0 47 | 48 | 49 | org.springframework.cloud 50 | spring-cloud-starter-netflix-hystrix 51 | 2.0.2.RELEASE 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-maven-plugin 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/src/main/java/com/web/gmall/BootOrderServiceConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 6 | import org.springframework.context.annotation.ImportResource; 7 | 8 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; 9 | 10 | @EnableHystrix 11 | @EnableDubbo(scanBasePackages={"com.web.gmall.service.impl"}) 12 | //@ImportResource(value={"classpath:consumer.xml"}) 13 | @SpringBootApplication 14 | public class BootOrderServiceConsumerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(BootOrderServiceConsumerApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/src/main/java/com/web/gmall/config/MyDubboConfig.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import com.alibaba.dubbo.config.ApplicationConfig; 10 | import com.alibaba.dubbo.config.ConsumerConfig; 11 | import com.alibaba.dubbo.config.MethodConfig; 12 | import com.alibaba.dubbo.config.MonitorConfig; 13 | import com.alibaba.dubbo.config.ReferenceConfig; 14 | import com.alibaba.dubbo.config.RegistryConfig; 15 | import com.web.gmall.service.UserService; 16 | 17 | @Configuration 18 | public class MyDubboConfig { 19 | 20 | @Bean 21 | public ApplicationConfig applicationConfig() { 22 | ApplicationConfig applicationConfig = new ApplicationConfig(); 23 | applicationConfig.setName("boot-order-service-consumer"); 24 | return applicationConfig; 25 | } 26 | 27 | // 28 | @Bean 29 | public RegistryConfig registryConfig() { 30 | RegistryConfig registryConfig = new RegistryConfig(); 31 | registryConfig.setProtocol("zookeeper"); 32 | registryConfig.setAddress("127.0.0.1:2181"); 33 | return registryConfig; 34 | } 35 | 36 | 37 | /** 38 | * 40 | 41 | 42 | */ 43 | @Bean 44 | public ReferenceConfig userReferenceConfig(){ 45 | ReferenceConfig serviceConfig = new ReferenceConfig<>(); 46 | serviceConfig.setInterface(UserService.class); 47 | serviceConfig.setTimeout(5000); 48 | serviceConfig.setVersion("*"); 49 | serviceConfig.setRetries(3); 50 | 51 | //配置每一个method的信息 52 | MethodConfig methodConfig = new MethodConfig(); 53 | methodConfig.setName("getUserAddressList"); 54 | methodConfig.setTimeout(1000); 55 | 56 | //将method的设置关联到service配置中 57 | List methods = new ArrayList<>(); 58 | methods.add(methodConfig); 59 | serviceConfig.setMethods(methods); 60 | 61 | return serviceConfig; 62 | } 63 | // 64 | @Bean 65 | public ConsumerConfig consumerConfig() { 66 | ConsumerConfig consumerConfig = new ConsumerConfig(); 67 | consumerConfig.setCheck(false);; 68 | consumerConfig.setTimeout(5000); 69 | return consumerConfig; 70 | } 71 | // 72 | @Bean 73 | public MonitorConfig monitorConfig() { 74 | MonitorConfig monitorConfig = new MonitorConfig(); 75 | monitorConfig.setAddress("127.0.0.1:7070"); 76 | monitorConfig.setProtocol("registry"); 77 | return monitorConfig; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/src/main/java/com/web/gmall/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | 11 | import com.web.gmall.bean.UserAddress; 12 | import com.web.gmall.service.OrderService; 13 | 14 | 15 | @Controller 16 | public class OrderController { 17 | 18 | @Autowired 19 | OrderService orderService; 20 | 21 | @ResponseBody 22 | @RequestMapping("/initOrder") 23 | public List initOrder(@RequestParam("uid")String userId) { 24 | return orderService.initOrder(userId); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/src/main/java/com/web/gmall/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service.impl; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.alibaba.dubbo.config.annotation.Reference; 9 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 10 | import com.web.gmall.bean.UserAddress; 11 | import com.web.gmall.service.OrderService; 12 | import com.web.gmall.service.UserService; 13 | 14 | /** 15 | * 1、将服务提供者注册到注册中心(暴露服务) 16 | * 1)、导入dubbo依赖(2.6.2)\操作zookeeper的客户端(curator) 17 | * 2)、配置服务提供者 18 | * 19 | * 2、让服务消费者去注册中心订阅服务提供者的服务地址 20 | * @author lfy 21 | * 22 | */ 23 | @Service 24 | public class OrderServiceImpl implements OrderService { 25 | 26 | 27 | // @Reference(url="127.0.0.1:20882") 28 | @Reference(loadbalance="roundrobin") 29 | UserService userService; 30 | 31 | @HystrixCommand(fallbackMethod="hello") 32 | @Override 33 | public List initOrder(String userId) { 34 | System.out.println("用户id:"+userId); 35 | // 1、查询用户的收货地址 36 | List addressList = userService.getUserAddressList(userId); 37 | for (UserAddress userAddress : addressList) { 38 | System.out.println(userAddress.getUserAddress()); 39 | } 40 | return addressList; 41 | } 42 | 43 | public List hello(String userId) { 44 | // TODO Auto-generated method stub 45 | 46 | return Arrays.asList(new UserAddress(10, "测试地址", "1", "测试", "测试", "Y")); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 2 | 3 | #dubbo.application.name=boot-order-service-consumer 4 | #dubbo.registry.address=zookeeper://127.0.0.1:2181 5 | #dubbo.monitor.protocol=registry 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/src/main/resources/consumer.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/src/main/resources/dubbo.properties: -------------------------------------------------------------------------------- 1 | dubbo.registry.address=127.0.0.1:2181 2 | dubbo.registry.protocol=zookeeper 3 | dubbo.monitor.protocol=registry 4 | 5 | dubbo.reference.check=false 6 | dubbo.consumer.check=false 7 | dubbo.registry.check=false -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-order-service-consumer/src/test/java/com/web/gmall/BootOrderServiceConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootOrderServiceConsumerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jane.dubbo 7 | boot-user-service-provider 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | boot-user-service-provider-20881 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | com.jane.dubbo 40 | gmall-interface 41 | 0.0.1-SNAPSHOT 42 | 43 | 44 | 45 | com.alibaba.boot 46 | dubbo-spring-boot-starter 47 | 0.2.0 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 2.0.2.RELEASE 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/src/main/java/com/web/gmall/BootUserServiceProvider20881Application.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 6 | 7 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; 8 | 9 | @EnableHystrix 10 | @EnableDubbo(scanBasePackages={"com.web.gmall.service.impl"})//开启基于注解的dubbo功能 11 | @SpringBootApplication 12 | public class BootUserServiceProvider20881Application { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(BootUserServiceProvider20881Application.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/src/main/java/com/web/gmall/config/MyDubboConfig.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import com.alibaba.dubbo.config.ApplicationConfig; 10 | import com.alibaba.dubbo.config.MethodConfig; 11 | import com.alibaba.dubbo.config.MonitorConfig; 12 | import com.alibaba.dubbo.config.ProtocolConfig; 13 | import com.alibaba.dubbo.config.ProviderConfig; 14 | import com.alibaba.dubbo.config.RegistryConfig; 15 | import com.alibaba.dubbo.config.ServiceConfig; 16 | import com.web.gmall.service.UserService; 17 | 18 | @Configuration 19 | public class MyDubboConfig { 20 | 21 | @Bean 22 | public ApplicationConfig applicationConfig() { 23 | ApplicationConfig applicationConfig = new ApplicationConfig(); 24 | applicationConfig.setName("boot-user-service-provider"); 25 | return applicationConfig; 26 | } 27 | 28 | // 29 | @Bean 30 | public RegistryConfig registryConfig() { 31 | RegistryConfig registryConfig = new RegistryConfig(); 32 | registryConfig.setProtocol("zookeeper"); 33 | registryConfig.setAddress("127.0.0.1:2181"); 34 | return registryConfig; 35 | } 36 | 37 | // 38 | @Bean 39 | public ProtocolConfig protocolConfig() { 40 | ProtocolConfig protocolConfig = new ProtocolConfig(); 41 | protocolConfig.setName("dubbo"); 42 | protocolConfig.setPort(20881); 43 | return protocolConfig; 44 | } 45 | 46 | /** 47 | * 49 | 50 | 51 | */ 52 | @Bean 53 | public ServiceConfig userServiceConfig(UserService userService){ 54 | ServiceConfig serviceConfig = new ServiceConfig<>(); 55 | serviceConfig.setInterface(UserService.class); 56 | serviceConfig.setRef(userService); 57 | serviceConfig.setVersion("1.0.0"); 58 | 59 | //配置每一个method的信息 60 | MethodConfig methodConfig = new MethodConfig(); 61 | methodConfig.setName("getUserAddressList"); 62 | methodConfig.setTimeout(1000); 63 | 64 | //将method的设置关联到service配置中 65 | List methods = new ArrayList<>(); 66 | methods.add(methodConfig); 67 | serviceConfig.setMethods(methods); 68 | 69 | return serviceConfig; 70 | } 71 | 72 | // 73 | @Bean 74 | public ProviderConfig providerConfig() { 75 | ProviderConfig providerConfig = new ProviderConfig(); 76 | providerConfig.setTimeout(5000); 77 | return providerConfig; 78 | } 79 | // 80 | @Bean 81 | public MonitorConfig monitorConfig() { 82 | MonitorConfig monitorConfig = new MonitorConfig(); 83 | monitorConfig.setAddress("127.0.0.1:7070"); 84 | monitorConfig.setProtocol("registry"); 85 | return monitorConfig; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/src/main/java/com/web/gmall/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service.impl; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | import com.alibaba.dubbo.config.annotation.Service; 9 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 10 | import com.web.gmall.bean.UserAddress; 11 | import com.web.gmall.service.UserService; 12 | 13 | @Service 14 | @Component 15 | public class UserServiceImpl implements UserService { 16 | 17 | @HystrixCommand 18 | @Override 19 | public List getUserAddressList(String userId) { 20 | System.out.println("UserServiceImpl......20881.."); 21 | // TODO Auto-generated method stub 22 | UserAddress address1 = new UserAddress(1, "北京市昌平区宏福科技园综合楼3层", "1", "李老师", "010-56253825", "Y"); 23 | UserAddress address2 = new UserAddress(2, "深圳市宝安区西部硅谷大厦B座3层(深圳分校)", "1", "王老师", "010-56253825", "N"); 24 | /*try { 25 | Thread.sleep(4000); 26 | } catch (InterruptedException e) { 27 | // TODO Auto-generated catch block 28 | e.printStackTrace(); 29 | }*/ 30 | return Arrays.asList(address1,address2); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20881/src/test/java/com/web/gmall/BootUserServiceProvider20881ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootUserServiceProvider20881ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jane.dubbo 7 | boot-user-service-provider 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | boot-user-service-provider-20882 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | com.jane.dubbo 40 | gmall-interface 41 | 0.0.1-SNAPSHOT 42 | 43 | 44 | 45 | com.alibaba.boot 46 | dubbo-spring-boot-starter 47 | 0.2.0 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 2.0.2.RELEASE 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/src/main/java/com/web/gmall/BootUserServiceProvider20882Application.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 6 | 7 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; 8 | 9 | import net.bytebuddy.build.HashCodeAndEqualsPlugin.Enhance; 10 | 11 | @EnableHystrix 12 | @EnableDubbo(scanBasePackages={"com.web.gmall.service.impl"})//开启基于注解的dubbo功能 13 | @SpringBootApplication 14 | public class BootUserServiceProvider20882Application { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(BootUserServiceProvider20882Application.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/src/main/java/com/web/gmall/config/MyDubboConfig.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import com.alibaba.dubbo.config.ApplicationConfig; 10 | import com.alibaba.dubbo.config.MethodConfig; 11 | import com.alibaba.dubbo.config.MonitorConfig; 12 | import com.alibaba.dubbo.config.ProtocolConfig; 13 | import com.alibaba.dubbo.config.ProviderConfig; 14 | import com.alibaba.dubbo.config.RegistryConfig; 15 | import com.alibaba.dubbo.config.ServiceConfig; 16 | import com.web.gmall.service.UserService; 17 | 18 | @Configuration 19 | public class MyDubboConfig { 20 | 21 | @Bean 22 | public ApplicationConfig applicationConfig() { 23 | ApplicationConfig applicationConfig = new ApplicationConfig(); 24 | applicationConfig.setName("boot-user-service-provider"); 25 | return applicationConfig; 26 | } 27 | 28 | // 29 | @Bean 30 | public RegistryConfig registryConfig() { 31 | RegistryConfig registryConfig = new RegistryConfig(); 32 | registryConfig.setProtocol("zookeeper"); 33 | registryConfig.setAddress("127.0.0.1:2181"); 34 | return registryConfig; 35 | } 36 | 37 | // 38 | @Bean 39 | public ProtocolConfig protocolConfig() { 40 | ProtocolConfig protocolConfig = new ProtocolConfig(); 41 | protocolConfig.setName("dubbo"); 42 | protocolConfig.setPort(20882); 43 | return protocolConfig; 44 | } 45 | 46 | /** 47 | * 49 | 50 | 51 | */ 52 | @Bean 53 | public ServiceConfig userServiceConfig(UserService userService){ 54 | ServiceConfig serviceConfig = new ServiceConfig<>(); 55 | serviceConfig.setInterface(UserService.class); 56 | serviceConfig.setRef(userService); 57 | serviceConfig.setVersion("1.0.0"); 58 | 59 | //配置每一个method的信息 60 | MethodConfig methodConfig = new MethodConfig(); 61 | methodConfig.setName("getUserAddressList"); 62 | methodConfig.setTimeout(1000); 63 | 64 | //将method的设置关联到service配置中 65 | List methods = new ArrayList<>(); 66 | methods.add(methodConfig); 67 | serviceConfig.setMethods(methods); 68 | 69 | return serviceConfig; 70 | } 71 | 72 | // 73 | @Bean 74 | public ProviderConfig providerConfig() { 75 | ProviderConfig providerConfig = new ProviderConfig(); 76 | providerConfig.setTimeout(5000); 77 | return providerConfig; 78 | } 79 | // 80 | @Bean 81 | public MonitorConfig monitorConfig() { 82 | MonitorConfig monitorConfig = new MonitorConfig(); 83 | monitorConfig.setAddress("127.0.0.1:7070"); 84 | monitorConfig.setProtocol("registry"); 85 | return monitorConfig; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/src/main/java/com/web/gmall/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service.impl; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | import com.alibaba.dubbo.config.annotation.Service; 9 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 10 | import com.web.gmall.bean.UserAddress; 11 | import com.web.gmall.service.UserService; 12 | 13 | @Service 14 | @Component 15 | public class UserServiceImpl implements UserService { 16 | 17 | @HystrixCommand 18 | @Override 19 | public List getUserAddressList(String userId) { 20 | System.out.println("UserServiceImpl......20882.."); 21 | // TODO Auto-generated method stub 22 | UserAddress address1 = new UserAddress(1, "北京市昌平区宏福科技园综合楼3层", "1", "李老师", "010-56253825", "Y"); 23 | UserAddress address2 = new UserAddress(2, "深圳市宝安区西部硅谷大厦B座3层(深圳分校)", "1", "王老师", "010-56253825", "N"); 24 | /*try { 25 | Thread.sleep(4000); 26 | } catch (InterruptedException e) { 27 | // TODO Auto-generated catch block 28 | e.printStackTrace(); 29 | }*/ 30 | return Arrays.asList(address1,address2); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider-20882/src/test/java/com/web/gmall/BootUserServiceProvider20882ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootUserServiceProvider20882ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper-new/boot-user-service-provider/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/bin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/bin/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper-new/boot-user-service-provider/bin/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/bin/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/bin/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/bin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jane.dubbo 7 | boot-user-service-provider 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | boot-user-service-provider 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/bin/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper-new/boot-user-service-provider/bin/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jane.dubbo 7 | boot-user-service-provider 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | boot-user-service-provider 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | com.jane.dubbo 40 | gmall-interface 41 | 0.0.1-SNAPSHOT 42 | 43 | 44 | 45 | com.alibaba.boot 46 | dubbo-spring-boot-starter 47 | 0.2.0 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 2.0.2.RELEASE 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/src/main/java/com/web/gmall/BootUserServiceProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 6 | 7 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; 8 | 9 | 10 | @EnableHystrix 11 | @EnableDubbo(scanBasePackages={"com.web.gmall.service.impl"})//开启基于注解的dubbo功能 12 | //@ImportResource(value={"classpath:provider.xml"}) 13 | @SpringBootApplication 14 | public class BootUserServiceProviderApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(BootUserServiceProviderApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/src/main/java/com/web/gmall/config/MyDubboConfig.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import com.alibaba.dubbo.config.ApplicationConfig; 10 | import com.alibaba.dubbo.config.MethodConfig; 11 | import com.alibaba.dubbo.config.MonitorConfig; 12 | import com.alibaba.dubbo.config.ProtocolConfig; 13 | import com.alibaba.dubbo.config.ProviderConfig; 14 | import com.alibaba.dubbo.config.RegistryConfig; 15 | import com.alibaba.dubbo.config.ServiceConfig; 16 | import com.web.gmall.service.UserService; 17 | 18 | @Configuration 19 | public class MyDubboConfig { 20 | 21 | @Bean 22 | public ApplicationConfig applicationConfig() { 23 | ApplicationConfig applicationConfig = new ApplicationConfig(); 24 | applicationConfig.setName("boot-user-service-provider"); 25 | return applicationConfig; 26 | } 27 | 28 | // 29 | @Bean 30 | public RegistryConfig registryConfig() { 31 | RegistryConfig registryConfig = new RegistryConfig(); 32 | registryConfig.setProtocol("zookeeper"); 33 | registryConfig.setAddress("127.0.0.1:2181"); 34 | return registryConfig; 35 | } 36 | 37 | // 38 | @Bean 39 | public ProtocolConfig protocolConfig() { 40 | ProtocolConfig protocolConfig = new ProtocolConfig(); 41 | protocolConfig.setName("dubbo"); 42 | protocolConfig.setPort(20880); 43 | return protocolConfig; 44 | } 45 | 46 | /** 47 | * 49 | 50 | 51 | */ 52 | @Bean 53 | public ServiceConfig userServiceConfig(UserService userService){ 54 | ServiceConfig serviceConfig = new ServiceConfig<>(); 55 | serviceConfig.setInterface(UserService.class); 56 | serviceConfig.setRef(userService); 57 | serviceConfig.setVersion("1.0.0"); 58 | 59 | //配置每一个method的信息 60 | MethodConfig methodConfig = new MethodConfig(); 61 | methodConfig.setName("getUserAddressList"); 62 | methodConfig.setTimeout(1000); 63 | 64 | //将method的设置关联到service配置中 65 | List methods = new ArrayList<>(); 66 | methods.add(methodConfig); 67 | serviceConfig.setMethods(methods); 68 | 69 | return serviceConfig; 70 | } 71 | 72 | // 73 | @Bean 74 | public ProviderConfig providerConfig() { 75 | ProviderConfig providerConfig = new ProviderConfig(); 76 | providerConfig.setTimeout(5000); 77 | return providerConfig; 78 | } 79 | // 80 | @Bean 81 | public MonitorConfig monitorConfig() { 82 | MonitorConfig monitorConfig = new MonitorConfig(); 83 | monitorConfig.setAddress("127.0.0.1:7070"); 84 | monitorConfig.setProtocol("registry"); 85 | return monitorConfig; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/src/main/java/com/web/gmall/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service.impl; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | import com.alibaba.dubbo.config.annotation.Service; 9 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 10 | import com.web.gmall.bean.UserAddress; 11 | import com.web.gmall.service.UserService; 12 | 13 | @Service(weight=200) 14 | @Component 15 | public class UserServiceImpl implements UserService { 16 | 17 | @HystrixCommand 18 | @Override 19 | public List getUserAddressList(String userId) { 20 | System.out.println("UserServiceImpl......20880.."); 21 | // TODO Auto-generated method stub 22 | UserAddress address1 = new UserAddress(1, "北京市昌平区宏福科技园综合楼3层", "1", "李老师", "010-56253825", "Y"); 23 | UserAddress address2 = new UserAddress(2, "深圳市宝安区西部硅谷大厦B座3层(深圳分校)", "1", "王老师", "010-56253825", "N"); 24 | /*try { 25 | Thread.sleep(4000); 26 | } catch (InterruptedException e) { 27 | // TODO Auto-generated catch block 28 | e.printStackTrace(); 29 | }*/ 30 | //随机抛出异常 31 | // if(Math.random()>0.5) { 32 | // throw new RuntimeException(); 33 | // } 34 | return Arrays.asList(address1,address2); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #dubbo.application.name=user-service-provider 2 | #dubbo.registry.address=127.0.0.1:2181 3 | #dubbo.registry.protocol=zookeeper 4 | # 5 | #dubbo.protocol.name=dubbo 6 | #dubbo.protocol.port=20881 7 | # 8 | #dubbo.monitor.protocol=registry 9 | #dubbo.scan.base-packages=com.web.gmall 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/src/main/resources/dubbo.properties: -------------------------------------------------------------------------------- 1 | dubbo.registry.address=127.0.0.1:2181 2 | dubbo.registry.protocol=zookeeper 3 | dubbo.monitor.protocol=registry -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/src/main/resources/provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/boot-user-service-provider/src/test/java/com/web/gmall/BootUserServiceProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootUserServiceProviderApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/gmall-interface/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.jane.dubbo 4 | gmall-interface 5 | 0.0.1-SNAPSHOT 6 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/gmall-interface/src/main/java/com/web/gmall/bean/UserAddress.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 用户地址 7 | * @author janus 8 | * 9 | */ 10 | public class UserAddress implements Serializable { 11 | 12 | private static final long serialVersionUID = 1L; 13 | private Integer id; 14 | private String userAddress; //用户地址 15 | private String userId; //用户id 16 | private String consignee; //收货人 17 | private String phoneNum; //电话号码 18 | private String isDefault; //是否为默认地址 Y-是 N-否 19 | 20 | public UserAddress() { 21 | super(); 22 | // TODO Auto-generated constructor stub 23 | } 24 | 25 | public UserAddress(Integer id, String userAddress, String userId, String consignee, String phoneNum, 26 | String isDefault) { 27 | super(); 28 | this.id = id; 29 | this.userAddress = userAddress; 30 | this.userId = userId; 31 | this.consignee = consignee; 32 | this.phoneNum = phoneNum; 33 | this.isDefault = isDefault; 34 | } 35 | 36 | public Integer getId() { 37 | return id; 38 | } 39 | public void setId(Integer id) { 40 | this.id = id; 41 | } 42 | public String getUserAddress() { 43 | return userAddress; 44 | } 45 | public void setUserAddress(String userAddress) { 46 | this.userAddress = userAddress; 47 | } 48 | public String getUserId() { 49 | return userId; 50 | } 51 | public void setUserId(String userId) { 52 | this.userId = userId; 53 | } 54 | public String getConsignee() { 55 | return consignee; 56 | } 57 | public void setConsignee(String consignee) { 58 | this.consignee = consignee; 59 | } 60 | public String getPhoneNum() { 61 | return phoneNum; 62 | } 63 | public void setPhoneNum(String phoneNum) { 64 | this.phoneNum = phoneNum; 65 | } 66 | public String getIsDefault() { 67 | return isDefault; 68 | } 69 | public void setIsDefault(String isDefault) { 70 | this.isDefault = isDefault; 71 | } 72 | 73 | 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/gmall-interface/src/main/java/com/web/gmall/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service; 2 | 3 | import java.util.List; 4 | 5 | import com.web.gmall.bean.UserAddress; 6 | 7 | public interface OrderService { 8 | 9 | /** 10 | * 初始化订单 11 | * @param userId 12 | */ 13 | public List initOrder(String userId); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/gmall-interface/src/main/java/com/web/gmall/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service; 2 | 3 | import java.util.List; 4 | 5 | import com.web.gmall.bean.UserAddress; 6 | 7 | /** 8 | * 用户服务 9 | * @author janus 10 | * 11 | */ 12 | public interface UserService { 13 | 14 | /** 15 | * 按照用户id返回所有的收货地址 16 | * @param userId 17 | * @return 18 | */ 19 | public List getUserAddressList(String userId); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/gmall-interface/src/main/java/com/web/gmall/service/stub/UserServiceStub.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service.stub; 2 | 3 | import java.util.List; 4 | 5 | import com.web.gmall.bean.UserAddress; 6 | import com.web.gmall.service.UserService; 7 | 8 | //本地存根 9 | public class UserServiceStub implements UserService { 10 | 11 | private final UserService userService; 12 | 13 | 14 | /** 15 | * 传入的是userService远程的代理对象 16 | * @param userService 17 | */ 18 | public UserServiceStub(UserService userService) { 19 | super(); 20 | this.userService = userService; 21 | } 22 | //如果用户id为空,则直接返回null,不会再进行远程调用 23 | @Override 24 | public List getUserAddressList(String userId) { 25 | // TODO Auto-generated method stub 26 | System.out.println("UserServiceStub....."); 27 | if(userId!=null&&userId!="") { 28 | return userService.getUserAddressList(userId); 29 | } 30 | return null; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/order-service-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.jane.dubbo 4 | order-service-consumer 5 | 0.0.1-SNAPSHOT 6 | 7 | 8 | 9 | com.jane.dubbo 10 | gmall-interface 11 | 0.0.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | com.alibaba 17 | dubbo 18 | 2.6.2 19 | 20 | 21 | 22 | org.apache.curator 23 | curator-framework 24 | 2.12.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/order-service-consumer/src/main/java/com/web/gmall/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import java.io.IOException; 4 | 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import com.web.gmall.service.OrderService; 8 | 9 | public class MainApplication { 10 | 11 | @SuppressWarnings("resource") 12 | public static void main(String[] args) throws IOException { 13 | ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("consumer.xml"); 14 | 15 | OrderService orderService = applicationContext.getBean(OrderService.class); 16 | 17 | orderService.initOrder("1"); 18 | System.out.println("调用完成...."); 19 | System.in.read(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/order-service-consumer/src/main/java/com/web/gmall/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | //import org.springframework.stereotype.Service; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.web.gmall.bean.UserAddress; 10 | import com.web.gmall.service.OrderService; 11 | import com.web.gmall.service.UserService; 12 | 13 | /** 14 | * 1、将服务提供者注册到注册中心(暴露服务) 15 | * 1)、导入dubbo依赖(2.6.2)\操作zookeeper的客户端(curator) 16 | * 2)、配置服务提供者 17 | * 18 | * 2、让服务消费者去注册中心订阅服务提供者的服务地址 19 | * @author lfy 20 | * 21 | */ 22 | @Service 23 | public class OrderServiceImpl implements OrderService { 24 | 25 | 26 | 27 | @Autowired 28 | UserService userService; 29 | 30 | @Override 31 | public List initOrder(String userId) { 32 | System.out.println("用户id:"+userId); 33 | // 1、查询用户的收货地址 34 | List addressList = userService.getUserAddressList(userId); 35 | for (UserAddress userAddress : addressList) { 36 | System.out.println(userAddress.getUserAddress()); 37 | } 38 | return addressList; 39 | } 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/order-service-consumer/src/main/resources/consumer.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/user-service-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.jane.dubbo 4 | user-service-provider 5 | 0.0.1-SNAPSHOT 6 | 7 | 8 | 9 | com.jane.dubbo 10 | gmall-interface 11 | 0.0.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | com.alibaba 17 | dubbo 18 | 2.6.2 19 | 20 | 21 | 22 | org.apache.curator 23 | curator-framework 24 | 2.12.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/user-service-provider/src/main/java/com/web/gmall/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall; 2 | 3 | import java.io.IOException; 4 | 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | public class MainApplication { 8 | 9 | public static void main(String[] args) throws IOException { 10 | ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("provider.xml"); 11 | ioc.start(); 12 | //阻塞等待读入字节 13 | System.in.read(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/user-service-provider/src/main/java/com/web/gmall/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service.impl; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import com.web.gmall.bean.UserAddress; 7 | import com.web.gmall.service.UserService; 8 | 9 | public class UserServiceImpl implements UserService { 10 | 11 | @Override 12 | public List getUserAddressList(String userId) { 13 | System.out.println("UserServiceImpl......1.."); 14 | // TODO Auto-generated method stub 15 | UserAddress address1 = new UserAddress(1, "北京市昌平区宏福科技园综合楼3层", "1", "李老师", "010-56253825", "Y"); 16 | UserAddress address2 = new UserAddress(2, "深圳市宝安区西部硅谷大厦B座3层(深圳分校)", "1", "王老师", "010-56253825", "N"); 17 | /*try { 18 | Thread.sleep(4000); 19 | } catch (InterruptedException e) { 20 | // TODO Auto-generated catch block 21 | e.printStackTrace(); 22 | }*/ 23 | return Arrays.asList(address1,address2); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/user-service-provider/src/main/java/com/web/gmall/service/impl/UserServiceImpl2.java: -------------------------------------------------------------------------------- 1 | package com.web.gmall.service.impl; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import com.web.gmall.bean.UserAddress; 7 | import com.web.gmall.service.UserService; 8 | 9 | public class UserServiceImpl2 implements UserService { 10 | 11 | @Override 12 | public List getUserAddressList(String userId) { 13 | System.out.println("UserServiceImpl......2.."); 14 | // TODO Auto-generated method stub 15 | UserAddress address1 = new UserAddress(1, "北京市昌平区宏福科技园综合楼3层", "1", "李老师", "010-56253825", "Y"); 16 | UserAddress address2 = new UserAddress(2, "深圳市宝安区西部硅谷大厦B座3层(深圳分校)", "1", "王老师", "010-56253825", "N"); 17 | /*try { 18 | Thread.sleep(4000); 19 | } catch (InterruptedException e) { 20 | // TODO Auto-generated catch block 21 | e.printStackTrace(); 22 | }*/ 23 | return Arrays.asList(address1,address2); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper-new/user-service-provider/src/main/resources/provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | consumer-user 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | consumer-user 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.12.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | com.alibaba.boot 35 | dubbo-spring-boot-starter 36 | 0.1.0 37 | 38 | 39 | 40 | 41 | 42 | com.github.sgroschupf 43 | zkclient 44 | 0.1 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-test 51 | test 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-maven-plugin 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/src/main/java/com/dubbo/consumer/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ConsumerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ConsumerApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/src/main/java/com/dubbo/consumer/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.consumer.service; 2 | 3 | import com.alibaba.dubbo.config.annotation.Reference; 4 | import com.dubbo.provider.service.TicketService; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * Created by Janus on 2018/7/11. 9 | */ 10 | @Service 11 | public class UserService { 12 | 13 | // 远程引用,按照全类名从注册中心寻找 14 | @Reference 15 | TicketService ticketService; 16 | 17 | public void hello(){ 18 | String ticket = ticketService.getTicket(); 19 | System.out.println("买到票了:"+ticket); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/src/main/java/com/dubbo/provider/ProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProviderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/src/main/java/com/dubbo/provider/service/TicketService.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.provider.service; 2 | 3 | /** 4 | * Created by Janus on 2018/7/11. 5 | */ 6 | public interface TicketService { 7 | 8 | public String getTicket(); 9 | } 10 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | dubbo.application.name=consumer-user 2 | 3 | dubbo.registry.address=zookeeper://192.168.2.110:2181 -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/src/test/java/com/dubbo/consumer/ConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.consumer; 2 | 3 | import com.dubbo.consumer.service.UserService; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class ConsumerApplicationTests { 13 | 14 | @Autowired 15 | UserService userService; 16 | 17 | @Test 18 | public void contextLoads() { 19 | userService.hello(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/target/classes/application.properties: -------------------------------------------------------------------------------- 1 | dubbo.application.name=consumer-user 2 | 3 | dubbo.registry.address=zookeeper://192.168.2.110:2181 -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/target/classes/com/dubbo/consumer/ConsumerApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/consumer-user/target/classes/com/dubbo/consumer/ConsumerApplication.class -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/target/classes/com/dubbo/consumer/service/UserService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/consumer-user/target/classes/com/dubbo/consumer/service/UserService.class -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/target/classes/com/dubbo/provider/ProviderApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/consumer-user/target/classes/com/dubbo/provider/ProviderApplication.class -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/target/classes/com/dubbo/provider/service/TicketService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/consumer-user/target/classes/com/dubbo/provider/service/TicketService.class -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/consumer-user/target/test-classes/com/dubbo/consumer/ConsumerApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/consumer-user/target/test-classes/com/dubbo/consumer/ConsumerApplicationTests.class -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | provider-ticket 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | provider-ticket 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.12.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | com.alibaba.boot 34 | dubbo-spring-boot-starter 35 | 0.1.0 36 | 37 | 38 | 39 | 40 | 41 | com.github.sgroschupf 42 | zkclient 43 | 0.1 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/src/main/java/com/dubbo/provider/ProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProviderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/src/main/java/com/dubbo/provider/service/TicketService.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.provider.service; 2 | 3 | /** 4 | * Created by Janus on 2018/7/11. 5 | */ 6 | public interface TicketService { 7 | 8 | public String getTicket(); 9 | } 10 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/src/main/java/com/dubbo/provider/service/impl/TicketServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.provider.service.impl; 2 | 3 | import com.alibaba.dubbo.config.annotation.Service; 4 | import com.dubbo.provider.service.TicketService; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by Janus on 2018/7/11. 9 | */ 10 | @Component 11 | @Service//将服务发布出去 12 | public class TicketServiceImpl implements TicketService { 13 | 14 | @Override 15 | public String getTicket() { 16 | return "《厉害了,我的国》"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | dubbo.application.name=provider-ticket 2 | 3 | dubbo.registry.address=zookeeper://192.168.2.110:2181 4 | 5 | dubbo.scan.base-packages=com.dubbo.provider.service -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/src/test/java/com/dubbo/provider/ProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dubbo.provider; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProviderApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/target/classes/application.properties: -------------------------------------------------------------------------------- 1 | dubbo.application.name=provider-ticket 2 | 3 | dubbo.registry.address=zookeeper://192.168.2.110:2181 4 | 5 | dubbo.scan.base-packages=com.dubbo.provider.service -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/target/classes/com/dubbo/provider/ProviderApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/provider-ticket/target/classes/com/dubbo/provider/ProviderApplication.class -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/target/classes/com/dubbo/provider/service/TicketService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/provider-ticket/target/classes/com/dubbo/provider/service/TicketService.class -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/target/classes/com/dubbo/provider/service/impl/TicketServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/provider-ticket/target/classes/com/dubbo/provider/service/impl/TicketServiceImpl.class -------------------------------------------------------------------------------- /springboot+dubbo+zookeeper/provider-ticket/target/test-classes/com/dubbo/provider/ProviderApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JanusJ/SpringBoot/1e0735589def6d65956df4c1a0acb610899a9d2a/springboot+dubbo+zookeeper/provider-ticket/target/test-classes/com/dubbo/provider/ProviderApplicationTests.class --------------------------------------------------------------------------------