Dubbo笔记5——dubbo搭建web项目

1.创建提供者 03-provider-web工程

1.1创建工程

创建 Maven 的 web 工程,使用公共接口服务创建一个实现

package com.abc.provider;

import com.abc.service.SomeService;

public class SomeServiceImpl implements SomeService {
    @Override
    public String hello(String name) {
        System.out.println("执行提供者的hello()");
        return name;
    }
}
1.2 导入依赖
  • dubbo2.7.0 版本依赖
  • zk 客户端 curator 依赖
  • servlet 与 jsp 依赖
  • spring 相关依赖
  • spring 需要的 commons-logging 依赖
  • 自定义 00-api 依赖

        UTF-8
        1.8
        1.8
        
        4.3.16.RELEASE
    

    
        
        
            org.apache.curator
            curator-recipes
            2.13.0
        
        
            org.apache.curator
            curator-framework
            2.13.0
        

        
        
            org.apache.dubbo
            dubbo
            2.7.0
        

        
        
            org.springframework
            spring-beans
            ${spring-version}
        
        
            org.springframework
            spring-core
            ${spring-version}
        
        
            org.springframework
            spring-context
            ${spring-version}
        
        
            org.springframework
            spring-expression
            ${spring-version}
        
        
            org.springframework
            spring-aop
            ${spring-version}
        
        
            org.springframework
            spring-aspects
            ${spring-version}
        
        
            org.springframework
            spring-tx
            ${spring-version}
        
        
            org.springframework
            spring-jdbc
            ${spring-version}
        
        
            org.springframework
            spring-web
            ${spring-version}
        
        
            org.springframework
            spring-webmvc
            ${spring-version}
        

        
        
            commons-logging
            commons-logging
            1.2
        

        
        
            com.abc
            00-api
            1.0-SNAPSHOT
        

    

    
        03-provider-web
        
            
                
                    maven-clean-plugin
                    3.0.0
                
                
                
                    maven-resources-plugin
                    3.0.2
                
                
                    maven-compiler-plugin
                    3.7.0
                
                
                    maven-surefire-plugin
                    2.20.1
                
                
                    maven-war-plugin
                    3.2.0
                
                
                    maven-install-plugin
                    2.5.2
                
                
                    maven-deploy-plugin
                    2.8.2
                
            
        
    

1.3 web.xml
  
    
        contextConfigLocation
        classpath:spring-*.xml
    

    
    
        org.springframework.web.context.ContextLoaderListener
    
1.4 修改 spring-provider.xml


    
    

    
    

    
    

2.创建消费者 03-consumer-web

2.1 创建工程

创建 Maven 的 web 工程,导入的依赖与03-provider-web的pom相同

2.2 创建处理器
@Controller
public class SomeController {
    @Autowired
    private SomeService service;

    @RequestMapping("/some.do")
    public String someHandle() {
        String result = service.hello("China");
        System.out.println("消费者端接收到 = " +  result);
        return "/welcome.jsp";
    }
}
2.3 resources目录下配置spring-consumer.xml文件


    
    

    
    

    
    
2.4 webapp目录下定义欢迎页面index.jsp


Hello World! - consumer

2.5 webapp/WEB-INF下定义 web.xml

        CharacterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            utf-8
        
        
            forceEncoding
            true
        
    
    
        CharacterEncodingFilter
        /*
    

    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:spring-*.xml
        
        1
    
    
        springmvc
        
        *.do
    

你可能感兴趣的:(Dubbo,dubbo,web)