增加spring dubbo 用例
This commit is contained in:
		
							
								
								
									
										40
									
								
								spring/spring-dubbo-annotation/dubbo-ano-provider/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								spring/spring-dubbo-annotation/dubbo-ano-provider/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<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/xsd/maven-4.0.0.xsd">
 | 
			
		||||
    <parent>
 | 
			
		||||
        <artifactId>spring-dubbo-annotation</artifactId>
 | 
			
		||||
        <groupId>com.heibaiying</groupId>
 | 
			
		||||
        <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </parent>
 | 
			
		||||
    <modelVersion>4.0.0</modelVersion>
 | 
			
		||||
 | 
			
		||||
    <artifactId>dubbo-ano-provider</artifactId>
 | 
			
		||||
 | 
			
		||||
    <build>
 | 
			
		||||
        <plugins>
 | 
			
		||||
            <plugin>
 | 
			
		||||
                <groupId>org.apache.maven.plugins</groupId>
 | 
			
		||||
                <artifactId>maven-compiler-plugin</artifactId>
 | 
			
		||||
                <version>3.5.1</version>
 | 
			
		||||
                <configuration>
 | 
			
		||||
                    <source>1.8</source>
 | 
			
		||||
                    <target>1.8</target>
 | 
			
		||||
                </configuration>
 | 
			
		||||
            </plugin>
 | 
			
		||||
        </plugins>
 | 
			
		||||
    </build>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.heibaiying</groupId>
 | 
			
		||||
            <artifactId>dubbo-ano-common</artifactId>
 | 
			
		||||
            <version>1.0-SNAPSHOT</version>
 | 
			
		||||
            <!-- compile 默认值 表示被依赖项目需要参与当前项目的编译,还有后续的测试,
 | 
			
		||||
            运行周期也参与其中,是一个比较强的依赖。打包的时候通常需要包含进去-->
 | 
			
		||||
            <scope>compile</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
    </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,22 @@
 | 
			
		||||
package com.heibaiying.config;
 | 
			
		||||
 | 
			
		||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author : heibaiying
 | 
			
		||||
 * @description :
 | 
			
		||||
 */
 | 
			
		||||
public class DispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
 | 
			
		||||
 | 
			
		||||
    protected Class<?>[] getRootConfigClasses() {
 | 
			
		||||
        return new Class[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected Class<?>[] getServletConfigClasses() {
 | 
			
		||||
        return new Class[]{ServletConfig.class};
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected String[] getServletMappings() {
 | 
			
		||||
        return new String[]{"/"};
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package com.heibaiying.config;
 | 
			
		||||
 | 
			
		||||
import com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.ComponentScan;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
import org.springframework.web.servlet.ViewResolver;
 | 
			
		||||
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
 | 
			
		||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
 | 
			
		||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 | 
			
		||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author : heibaiying
 | 
			
		||||
 * @description : 主配置类
 | 
			
		||||
 */
 | 
			
		||||
@Configuration
 | 
			
		||||
@EnableWebMvc
 | 
			
		||||
@DubboComponentScan(basePackages = "com.heibaiying.service") // 扫描dubbo注解
 | 
			
		||||
@ComponentScan(basePackages = {"com.heibaiying.*"})
 | 
			
		||||
public class ServletConfig implements WebMvcConfigurer {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
package com.heibaiying.config.dubbo;
 | 
			
		||||
 | 
			
		||||
import com.alibaba.dubbo.config.ApplicationConfig;
 | 
			
		||||
import com.alibaba.dubbo.config.RegistryConfig;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author : heibaiying
 | 
			
		||||
 * @description : dubbo 配置类
 | 
			
		||||
 */
 | 
			
		||||
@Configuration
 | 
			
		||||
public class DubboConfiguration {
 | 
			
		||||
 | 
			
		||||
    @Bean
 | 
			
		||||
    public ApplicationConfig applicationConfig() {
 | 
			
		||||
        ApplicationConfig applicationConfig = new ApplicationConfig();
 | 
			
		||||
        applicationConfig.setName("dubbo-ano-provider");
 | 
			
		||||
        return applicationConfig;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Bean
 | 
			
		||||
    public RegistryConfig registryConfig() {
 | 
			
		||||
        RegistryConfig registryConfig = new RegistryConfig();
 | 
			
		||||
        registryConfig.setAddress("zookeeper://127.0.0.1:2181");
 | 
			
		||||
        registryConfig.setClient("curator");
 | 
			
		||||
        return registryConfig;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,40 @@
 | 
			
		||||
package com.heibaiying.service;
 | 
			
		||||
 | 
			
		||||
import com.alibaba.dubbo.config.annotation.Service;
 | 
			
		||||
import com.heibaiying.api.IProductService;
 | 
			
		||||
import com.heibaiying.bean.Product;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author : heibaiying
 | 
			
		||||
 * @description : 产品提供接口实现类
 | 
			
		||||
 */
 | 
			
		||||
@Service(timeout = 5000)
 | 
			
		||||
public class ProductService implements IProductService {
 | 
			
		||||
 | 
			
		||||
    private static List<Product> productList = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    static {
 | 
			
		||||
        for (int i = 0; i < 20; i++) {
 | 
			
		||||
            productList.add(new Product(i, "产品" + i, i / 2 == 0, new Date(), 66.66f * i));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Product queryProductById(int id) {
 | 
			
		||||
        for (Product product : productList) {
 | 
			
		||||
            if (product.getId() == id) {
 | 
			
		||||
                return product;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public List<Product> queryAllProducts() {
 | 
			
		||||
        return productList;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,6 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 | 
			
		||||
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
 | 
			
		||||
         version="4.0">
 | 
			
		||||
</web-app>
 | 
			
		||||
@@ -0,0 +1,9 @@
 | 
			
		||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
    <title>Title</title>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
    hello dubbo provider!
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user