Springboot + mybatis+dubbo+zookeeper+nginx+redis+html__html

Source: Internet
Author: User
Tags aop generator zookeeper

Comprehensive learning Springboot+dubbo+zookeeper, combined with the usual framework, the common framework for the integration of a bit, from the frame to the background to the front, if there is infringement, please contact delete.

Background frame Springboot+mybatis+dubbo+zookeeper+redis+nginx, which redis do data caching, Nginx do page forwarding, database with MySQL. First, the Springboot-mybatis-dubbo-zookeeper directory schema is as follows:



The Pom files for the first project's outer definition version are as follows:

<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" > < Modelversion>4.0.0</modelversion> <groupId>com.cn.bee</groupId> <artifactId> Springboot-mybatis-dubbo-zookeeper</artifactid> <version>0.0.1-SNAPSHOT</version> < Packaging>pom</packaging> <name>springboot-mybatis-dubbo-zookeeper</name> <description& Gt;springboot-mybatis-dubbo-zookeeper</description> <properties> <jdk.version>1.7</jdk. Version> <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version> <maven-resou Rces-plugin.version>2.6</maven-resources-plugin.version> <org.mybatis.generator.version>1.3.2 </org.mybatis.generator.version> <mybatis.version>3.1.1</mybatis.version> <mybatis-spring.version>1.2.0</mybatis-spring.version> <mybatis- Spring-boot>1.2.0</mybatis-spring-boot> <dubbo.version>2.5.3</dubbo.version> <zook Eeper.version>3.3.6</zookeeper.version> <zkclient.version>0.1</zkclient.version> < Com.alibaba.druid.version>0.2.6</com.alibaba.druid.version> <spring-boot-starter-redis-version> 1.3.2.release</spring-boot-starter-redis-version> </properties> <!--springboot Use the 1.4.1.RELEASE version- > <parent> <groupId>org.springframework.boot</groupId> <artifactid>spring-b oot-starter-parent</artifactid> <version>1.5.1.RELEASE</version> </parent> <bu ild> <plugins> <plugin> <groupid>org.apache.maven.plugins</gro Upid>;artifactid>maven-compiler-plugin</artifactid> <configuration> <sour Ce>${jdk.version}</source> <target>${jdk.version}</target> &L t;encoding>utf-8</encoding> </configuration> </plugin> <p Lugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>maven- Resources-plugin</artifactid> <configuration> <encoding>utf-8</en
    
    coding> </configuration> </plugin> </plugins> </build>
        <modules> <!--mainly put the entity, interface, also can put some common tools engineering--> <module>edu-web-common</module> <!--service Provider Engineering--> <module>edu-web-server</module> <!--service Consumer engineering--> ; Module>edu-web-clienT</module> </modules> <!--http://blog.csdn.net/shawearn1027/article/details/55098024--> </
 Project>
edu-web-clientThe following Application.java, which mainly uses annotations to load beans, and the startup main method of the service provider is also written below, the code reads as follows:

@MapperScan ("Com.cn.bee.dao") @SpringBootApplication @ImportResource (locations={"Dubbo-provider.xml"}) public Class Application {/** * 1. After starting the app layer Main method, the bean is automatically loaded, @ConfigurationProperties (prefix= "Spring.datasource") automatically goes to the AP Plication.properties * The following configuration file for database connections, beginning with Spring.datasource * 2. Automatically scans MyBatis Mapp by annotation @mapperscan ("Com.cn.bee.dao")

    ER file */private static volatile Boolean running = true;

    private static Logger Logger = Logger.getlogger (Application.class);
        DataSource configuration @Bean @ConfigurationProperties (prefix= "Spring.datasource") Public datasource DataSource () {
    return new Com.alibaba.druid.pool.DruidDataSource (); //Provide sqlseesion @Bean public sqlsessionfactory Sqlsessionfactorybean () throws Exception {Sqlsessio
        Nfactorybean Sqlsessionfactorybean = new Sqlsessionfactorybean ();

        Sqlsessionfactorybean.setdatasource (DataSource ()); Pathmatchingresourcepatternresolver resolver = new PathmatchingrEsourcepatternresolver (); Configure mapper scans to find all mapper.xml mapping files sqlsessionfactorybean.setmapperlocations (resolver.getresources ("classpath:/
        Mapper/*.xml ")); Loads the global configuration file sqlsessionfactorybean.setconfiglocation (new Defaultresourceloader (). GetResource ("CLA

        Sspath:mybatis-config.xml "));
    return Sqlsessionfactorybean.getobject (); @Bean public Platformtransactionmanager TransactionManager () {return new Datasourcetransactionmanager (
    DataSource ()); }/** * Main method Startup entry/public static void Main (string[] args) {Springapplication.run (applicatio
        N.class, args);
        System.out.println ("============= APP Start on springboot Success ============="); Synchronized (Application.class) {while (running) {try {Application.cla
                Ss.wait (); The catch (Throwable e) {}}}}
When you start the Edu-web-client Main method, the bean is loaded automatically, @ConfigurationProperties (prefix= "Spring.datasource") will automatically go to application.properties the following configuration file for the database connection, beginning with Spring.datasource, application.properties as follows:

Spring.datasource.url=jdbc:mysql://localhost:3306/springbootdb?useunicode=true&characterencoding=utf8
Spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name= Com.mysql.jdbc.Driver

dubbo.registry.center=127.0.0.1:2181
dubbo.protocol.port=20885

Dubbo-provider.xml of the service provider, the code is as follows:

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:aop= "Http://www.springframework.org/schema/aop" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns: task= "Http://www.springframework.org/schema/task" 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-3.1.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/aop/spring-aop-3.1.xsd Http://www.springframework.org/schema/context http: Www.springframework.org/schema/context/spring-context-3.1.xsd Http://www.springframework.org/schema/task http: Www.springframework.org/schema/task/spring-tasK.xsd Http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd Http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> &
                                Lt;context:component-scan base-package= "com.cn.bee.service.*" > <context:exclude-filter type= "Annotation" expression= "Org.springframework.stereotype.Controller"/> </context:component-scan&

    Gt <dubbo:application name= "Springboot-service-provider-app"/> <!--Dubbo Registered address--> <dubbo:registry Pro Tocol= "Zookeeper" address= "${dubbo.registry.center}"/> <dubbo:protocol name= "Dubbo" port= Dubbo.protocol.port} "threadpool=" Cached "threads=" 1000 "accepts=" serialization= "java"/> <dubbo:service Interface= "Com.cn.bee.service.UserService" ref= "UserService" timeout= "3000" ></dubbo:service> <dubbo: Service Interface= "Com.cn.bee.service.DiCtservice "ref=" Dictservice "timeout=" 3000 "></dubbo:service> <dubbo:service interface=" Com.cn.bee.service.AreaService "ref=" Areaservice "timeout=" 3000 "></dubbo:service> </beans>

Edu-web-client Other levels of code is omitted, there is a need to contact me to understand. At the same time, local can download a stand-alone version of the zookeeper

Edu-web-common: Main Place entity, interface, also can put some common tool class wait.

Here, our service can be completed, run application. Java Main method, we can see the console as follows, on behalf of success.


Then we go to edu-web-server, mainly to do the service side

Application.properties is as follows:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.