分布式学习day02

今天学习分布式的项目搭建,第二天使用 intelliJ IDEA 渐渐适应了操作

搭建分布式项目,我把他分为一个父工程和14个子工程

如图是各项目的关系依赖:

分布式学习day02_第1张图片

idea包结构:

分布式学习day02_第2张图片

搭建好我们所需要的工程之后,我们就需要配置XML文件和POM.xml文件

 父工程的POM文件                      



4.12
4.2.4.RELEASE
4.0.0
2.5
2.8.4
3.4.7
0.1
3.2.8
1.2.2
1.2.15
5.1.32
1.0.9
1.3.1
2.3.23
5.11.2
3.2.3.RELEASE
4.10.3
2012_u6







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


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


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


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


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


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


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


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



com.alibaba
dubbo
${dubbo.version}


org.apache.zookeeper
zookeeper
${zookeeper.version}


com.github.sgroschupf
zkclient
${zkclient.version}


junit
junit
4.9


com.alibaba
fastjson
1.2.28


javassist
javassist
3.11.0.GA


commons-codec
commons-codec
1.10


javax.servlet
servlet-api
2.5
provided


com.github.pagehelper
pagehelper
${pagehelper.version}



org.mybatis
mybatis
${mybatis.version}


org.mybatis
mybatis-spring
${mybatis.spring.version}


com.github.miemiedev
mybatis-paginator
${mybatis.paginator.version}



mysql
mysql-connector-java
${mysql.version}



com.alibaba
druid
${druid.version}


org.csource.fastdfs
fastdfs
1.2



commons-fileupload
commons-fileupload
${commons-fileupload.version}



redis.clients
jedis
2.8.1


org.springframework.data
spring-data-redis
1.7.2.RELEASE


org.freemarker
freemarker
${freemarker.version}


org.apache.activemq
activemq-all
${activemq.version}



org.springframework.security
spring-security-web
4.1.0.RELEASE


org.springframework.security
spring-security-config
4.1.0.RELEASE


com.github.penggle
kaptcha
2.3.2


javax.servlet
javax.servlet-api




org.springframework.security
spring-security-cas
4.1.0.RELEASE


org.jasig.cas.client
cas-client-core
3.3.3



org.slf4j
log4j-over-slf4j





org.apache.solr
solr-solrj
${solrj.version}


com.janeluo
ikanalyzer
${ik.version}


org.apache.httpcomponents
httpcore
4.4.4


org.apache.httpcomponents
httpclient
4.5.3


dom4j
dom4j
1.6.1


xml-apis
xml-apis
1.4.01

 common的pom文件



com.github.pagehelper
pagehelper



org.mybatis
mybatis


org.mybatis
mybatis-spring


com.github.miemiedev
mybatis-paginator



mysql
mysql-connector-java



com.alibaba
druid



org.csource.fastdfs
fastdfs


commons-fileupload
commons-fileupload



redis.clients
jedis


org.springframework.data
spring-data-redis


javax.servlet
servlet-api
provided


org.apache.httpcomponents
httpclient



org.springframework
spring-context


org.springframework
spring-beans


org.springframework
spring-webmvc


org.springframework
spring-jdbc


org.springframework
spring-aspects


org.springframework
spring-jms


org.springframework
spring-context-support


org.springframework
spring-test



com.alibaba
dubbo


org.apache.zookeeper
zookeeper


com.github.sgroschupf
zkclient


junit
junit


com.alibaba
fastjson


javassist
javassist


commons-codec
commons-codec


javax.servlet
servlet-api
provided


org.springframework.security
spring-security-web


org.springframework.security
spring-security-config


org.springframework.security
spring-security-cas


org.jasig.cas.client
cas-client-core


org.slf4j
log4j-over-slf4j





org.apache.activemq
activemq-client
5.13.4



org.freemarker
freemarker
2.3.23



com.github.wxpay
wxpay-sdk
0.0.3



org.springframework.data
spring-data-solr
1.5.5.RELEASE

这里指的是锁定版本号 真正实现依赖的是common pom.xml文件里的

配置好相关的web.xml文件后利用逆向工程将我们导入的数据库生成pojo实体类 dao接口 映射mapper文件
之后我们就只需要关心interface项目和service项目和web项目就行了
我们来测试一下如何查询数据库中的商品表!
首先在interface中写入一个接口:
package com.ujiuye.service;

import com.ujiuye.pojo.good.Brand;

import java.util.List;

public interface BrandService {

    public List findAll();
}

在service中实现这个接口

package com.ujiuye.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.ujiuye.dao.good.BrandDao;
import com.ujiuye.pojo.good.Brand;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Service
public class BrandServiceImpl implements BrandService{
    @Autowired
    private BrandDao brandDao;
    @Override
    public List findAll() {

        List brands = brandDao.selectByExample(null);
        return brands;
    }
}

controller层

package com.ujiuye.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ujiuye.pojo.good.Brand;
import com.ujiuye.service.BrandService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Brand")
public class BrandController {
    @Reference
    private BrandService brandService;
    @RequestMapping("/findAll")
    public List findAll(){
        List list = brandService.findAll();
        return list;
    }
}

部署tomcat 先启动service层后启动controller   注意端口号不要重复

启动zookeeper,接下来我们就可以测试我们的代码了!

在url栏输入我们的地址

可以看到 我们成功实现了利用分布式实现了查询数据库中的商品表,因为没有相关的页面 返回的是一个json格式的数据

 

 

你可能感兴趣的:(分布式学习day02)