dubbo整合zookeeper-Demo

一 、前提搭好zookeeper,创建项目,其中zmin-web和zmin-serivce为web,其余为module。

dubbo整合zookeeper-Demo_第1张图片

common存放公共的jar依赖

    
        UTF-8
        4.1.7.RELEASE
        1.8
    
    
        
        
            org.springframework
            spring-aop
            ${spring.version}
        

        
            org.springframework
            spring-context
            ${spring.version}
        

        
            org.springframework
            spring-context-support
            ${spring.version}
        

        
            org.springframework
            spring-core
            ${spring.version}
        
        
            org.springframework
            spring-expression
            ${spring.version}
        
        
            org.springframework
            spring-jdbc
            ${spring.version}
        
        
            org.springframework
            spring-aspects
            ${spring.version}
        
        
            org.springframework
            spring-mock
            2.0.8
        
        
            org.springframework
            spring-orm
            ${spring.version}
        
        
            org.springframework
            spring-tx
            ${spring.version}
        
        
            org.springframework
            spring-oxm
            ${spring.version}
        

        
            org.springframework
            spring-webmvc
            ${spring.version}
        

        
            org.springframework
            spring-web
            ${spring.version}
        

        
            org.mybatis
            mybatis-ehcache
            1.0.0
        

        
            org.mybatis
            mybatis
            3.2.1
        
        
            org.mybatis
            mybatis-spring
            1.2.0
        

        
            com.alibaba
            dubbo
            2.6.0
        
        
            com.101tec
            zkclient
            0.9
        

        
            mysql
            mysql-connector-java
            5.1.34
        
        
            com.alibaba
            druid
            1.0.9
        
        
            zmin
            zmin-bean
            1.0-SNAPSHOT
        
    

web层:

web.xml配置




  Archetype Created Web Application

  
  
    contextConfigLocation
    classpath:spring/applicationContext*.xml
  

  
  
    org.springframework.web.context.ContextLoaderListener
  
  
  
    springmvc-web
    org.springframework.web.servlet.DispatcherServlet
    
      contextConfigLocation
      classpath:spring/springmvc.xml 
    
  

  
    springmvc-web
    *.action
  

springmvc配置



    
    

dubbo消费方配置:



    
    
    
    

controller

package com.zmin.controller;

        import com.zmin.iservice.ITestService;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Controller;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.servlet.ModelAndView;

@Controller
public class TestController {
    @Autowired
    ITestService testService;

    @RequestMapping("test")
    public ModelAndView test(){
        ModelAndView mav = new ModelAndView();
        String testData = testService.getTest();
        System.out.print(testData);
        mav.setViewName("WEB-INF/hello.jsp");
        return  mav;
    }
}



Service层

web.xml配置(Spring托管配置)




  Archetype Created Web Application

  
  
    contextConfigLocation
    classpath*:spring/applicationContext*.xml
 
  

  
  
    org.springframework.web.context.ContextLoaderListener
  

dubbo消费方配置



    
    
    
    

    
    

    
    

    
    

    
    

service 代码

package com.zmin.service;

import com.zmin.bean.User;
import com.zmin.iservice.ITestService;
import com.zmin.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TestService implements ITestService {
    @Autowired
    UserMapper userMapper;
    @Override
    public String getTest() {
        User user = userMapper.selectByPrimaryKey(1);
        if(null == user){
            System.out.print("00000000000000000000000000000000");
        }
        return "你是谁";
    }
}

dao层



    
    
    

    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    


    
    
        
        
        
    

    
        
    

    
        
        
    

dao 代码(加个注解)

package com.zmin.mapper;

import com.zmin.bean.User;
import com.zmin.bean.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper {
    int countByExample(UserExample example);

    int deleteByExample(UserExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    int insertSelective(User record);

    List selectByExample(UserExample example);

    User selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);
}

 
  

相关位置

dubbo整合zookeeper-Demo_第2张图片



你可能感兴趣的:(Java)