欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springboot dubbox 实例 博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 

程序员文章站 2024-03-18 14:09:34
...

 ----------------------------------------------------------------------------------------------------------------

springboot 详解 (一) helloworld                                    下载demo          

springboot 详解 (二) crud                                             下载demo     

springboot 详解 (三) 多数据源                                        下载demo      

springboot 详解 (四)redis & filter                                    下载demo    

springboot 详解 (五)interceptor                                       下载demo     

springboot 详解 (六)servlet & scheduled & listener         下载demo     

springboot 详解(七) dubbox & zookeeper   下载(productor) 下载(constumser)

springboot 同步解耦 异步化 下载demo

springboot jenkins docker 部署 

springboot 详解(八) springboot & springcloud 

----------------------------------------------------------------------------------------------------------------

 

其他文章参考:

(阿里巴巴 dubbo,有数据库,可执行 )dubbo zookeeper spring demo

(webservice+cxf+mybatis+mysql+springmvc) webservice + cxf 能够跑起来的cxf ,来这里,,

 

 

 

 

 结果 如图 
springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 
springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 
springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 

pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.curiousby.cn</groupId>
  <artifactId>SpringBootDubboxDemo</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>SpringBootDubboxDemo Maven Webapp</name>
  <url>http://maven.apache.org</url>
  



    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
        </pluginRepository>
    </pluginRepositories>
    

	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.7</java.version>
    </properties>

    <dependencies>
    <dependency>  
          <groupId>org.springframework.boot</groupId>  
          <artifactId>spring-boot-starter-redis</artifactId>  
      </dependency> 
        <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
			<scope>runtime</scope>
		</dependency> 
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>
         
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.6</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
 
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.1</version>
        </dependency>
        
    </dependencies>

	<build>
		<finalName>SpringBootDubboxDemo</finalName>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<useSystemClassLoader>false</useSystemClassLoader>
				</configuration>
			</plugin>
			
		</plugins>

	</build>
	
</project>

 

 

 

 

SpringBootDubboxDemo-Productor

 

application.properties

server.context-path=/SpringBootDubboxDemoProductor


spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
application.hello=Hello baoyou

 
#one datasource
spring.datasource.url=jdbc:mysql://localhost:3306/database
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName=com.mysql.jdbc.Driver

 
 

 

applicationContext-dubbox-productor.xml

<?xml version="1.0" encoding="UTF-8"?>


<beans  xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
	xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:jms="http://www.springframework.org/schema/jms" 
	xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:mvc="http://www.springframework.org/schema/mvc" 
	xmlns:oxm="http://www.springframework.org/schema/oxm"
	xmlns:p="http://www.springframework.org/schema/p" 
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:tx="http://www.springframework.org/schema/tx" 
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
    http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
	default-autowire="byName"> 

	<context:annotation-config />
	<aop:aspectj-autoproxy /> 
	
	<!-- 提供方应用名称信息,这个相当于起一个名字,我们dubbo管理页面比较清晰是哪个应用暴露出来的 -->
	<dubbo:application name="dubbox-productor"></dubbo:application>
	<!--使用注解方式暴露接口 -->
	<!--<dubbo:annotation package="com.curiousby.cn.service" /> -->
	<!-- 使用zookeeper注册中心暴露服务地址 -->
	<dubbo:registry 
		address="zookeeper://dev10.aoiplus.openpf:2181"
		check="false" 
		subscribe="false" 
		register="">
		</dubbo:registry>
	<!-- 要暴露的服务接口 -->
	<dubbo:service interface="com.curiousby.cn.service.UserService" ref="userServiceImpl" />


</beans>

 

public interface UserService {
 
    
    public User  findById(int userId);

}

 

 

@Transactional
@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserDao userDao;

    @Override
    public User findById(int userId) {
        System.out.println("================productor==================="); 
        User user = userDao.findById(userId);
        System.out.println("================productor==================="+user);
        return user;
    }

}

 

@EnableTransactionManagement  //事务自动扫描
@SpringBootApplication  
@ImportResource({"classpath:applicationContext-dubbox-productor.xml"})
public class SpringBootSampleApplication {

    
     
    
    public static void main(String[] args) {
        SpringApplication.run(SpringBootSampleApplication.class, args);
    }


}

 

 

SpringBootDubboxDemo-Consumer

 

server.context-path=/SpringBootDubboxDemoConsumer


spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
application.hello=Hello baoyou

 
#one datasource
spring.datasource.url=jdbc:mysql://localhost:3306/database
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName=com.mysql.jdbc.Driver

 
server.port=9090
server.session-timeout=60
# server.address=192.168.16.11

 

 

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans          
    http://www.springframework.org/schema/beans/spring-beans.xsd          
    http://code.alibabatech.com/schema/dubbo          
    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
	<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
	<dubbo:application name="dubbox-consumer" />
	<dubbo:registry address="zookeeper://dev10.aoiplus.openpf:2181" />
	<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
	<dubbo:reference id="userService"  interface="com.curiousby.cn.service.UserService" />
	
</beans>

 

@EnableTransactionManagement  //事务自动扫描
@SpringBootApplication  
@ImportResource({"classpath:applicationContext-dubbox-consumer.xml"})
public class SpringBootSampleApplication {

    
     
    
    public static void main(String[] args) {
        SpringApplication.run(SpringBootSampleApplication.class, args);
    }


}

 

 

 

 

 

 

 


springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 
springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 
springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 
springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 
springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 
springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。


springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
 
 谢谢您的赞助,我会做的更好!

 

 

 

 

 

 

  • springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
  • 大小: 5.2 KB
  • springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
  • 大小: 3.1 KB
  • springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
  • 大小: 101.4 KB
  • springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
  • 大小: 186 KB
  • springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
  • 大小: 49.3 KB
  • springboot dubbox  实例
            
    
    博客分类: dubbospringspringbootzookeeper dubbospringspringbootzookeeper 
  • 大小: 53.2 KB