MAVEN multi-module +dubbo+zookeeper distributed architecture to build SSM project

Source: Internet
Author: User
Tags pack zookeeper

MAVEN Multi-Module build:

I. Overall structure preview

|----Parent Module

|-----Manage Polymerization Engineering module

| |------Pojo Class

| |------DAO Layer

| |------Service Interface Layer

| |------Service Implementation Layer

|-----Common Common components

|-----Web Presentation Layer

Parent class module: Centralized unified management project need jar package version number, packaging method Pom;

Manage Polymerization Engineering Module: inherits the parent module, centralized management Pojo, DAO, serivice each layer component, manage module packing way is POM package;

Pojo inherits manage modules, stores entity classes, and packages them as jars;

DAO inherits manage module, which is responsible for interacting with database and packaging as jar;

The service interface inherits the Manager module and provides the abstract interface of the Services module, which is packaged as a jar for exposing the external access interface.

Service implementation layer inherits the Manage module, implements the interface, realizes the business logic, packs the war;

Common common Component module: Inherit parent module, manage common component, such as log4j, pack as jar;

The Web presentation layer inherits the parent class directly, also for the controller layer, packaged as a war package, through the network communication and the Servic interface link, realizes the remote access; below starts to throw the actual combat code demonstration.

Second, the specific implementation of the business code, the project built for the SSM framework:

(1). jar package Management in parent module

<projectxmlns= "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.0http://maven.apache.org/xsd/maven-4.0.0.xsd ">

<modelVersion>4.0.0</modelVersion>

<groupId>com.ssm</groupId>

<artifactId>ssm-parent</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

<!--1. Manage the version of the jar pack-->

<properties>

<--here in the jar package version, the maintenance room only needs to update the JAR package version here, because of inheritance relationship, the subclass module directly updates-->

<zookeeper.version>3.4.7</zookeeper.version>

</properties>

<!--2. Add Jar pack-->

<dependencyManagement>

<dependencies>

<dependence>

Here, put the coordinates of the dependent file, the version with El expression can

<dependence>

</dependencies>

</dependencyManagement>

<build>

<finalName>${project.artifactId}</finalName>

<!--Configure Plug-ins-->

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.1</version>

<configuration>

<!--Configure the version of JDK-->

<source>1.8</source>

<target>1.8</target>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.tomcat.maven</groupId>

<artifactId>tomcat7-maven-plugin</artifactId>

<version>2.2</version>

<configuration>

<port>8080</port>

<uriEncoding>UTF-8</uriEncoding>

<server>tomcat7</server>

</configuration>

</plugin>

</plugins>

</build>

</project>

(2). Common Common Component module: to rely on the required jar package from the parent class into its own pom.xml

<projectxmlns= "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.0http://maven.apache.org/xsd/maven-4.0.0.xsd ">

<modelVersion>4.0.0</modelVersion>

<parent>

<groupId>com.ssm</groupId>

<artifactId>ssm-parent</artifactId>

<version>0.0.1-SNAPSHOT</version>

</parent>

<groupId>com.ssm</groupId>

<artifactId>ssm-common</artifactId>

<version>0.0.1-SNAPSHOT</version>

<dependencies>

<denpendence>

This writes the dependent file jar package coordinates

<dependence>

</dependencies>

</project>

(3). Manage module, this time the core of the overall business logic of the project, the establishment of the manage for the polymerization project, in the Manage polymerization project to establish model module, respectively, Pojo,dao,service, a level of serviceinterface,

After the module is completed, it will be displayed as follows in the parent class manage:

<modules>

<module>ssm-dao</module>

<module>ssm-service</module>

<module>ssm-pojo</module>

<module>ssm-interface</module>

</modules>

When the scale of the service cluster expands further, driving IT governance structure to further upgrade, dynamic deployment needs to be realized, and the existing distributed service architecture will not bring resistance:

<!--add dependencies, rely on common components-->

<dependencies>

<dependency>

<groupId>com.ssm</groupId>

<artifactId>ssm-common</artifactId>

<version>0.0.1-SNAPSHOT</version>

</dependency>

</dependencies>

<!--add compilation Plug-ins-->

<build>

<plugins>

<!--Tomcat plugin-->

<plugin>

<groupId>org.apache.tomcat.maven</groupId>

<artifactId>tomcat7-maven-plugin</artifactId>

<version>2.2</version>

<configuration>

<port>8080</port>

<path>/</path>

</configuration>

</plugin>

<!--JDK plugin-->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.1</version>

<configuration>

<!--Configure the version of JDK-->

<source>1.8</source>

<target>1.8</target>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

</plugins>

</build>

Here is not to repeat manage below the establishment of the sub-module, only to introduce the most important service, in the service layer need to integrate the spring and mybatis framework, so here to build the framework of the steps are no longer described, first look at the structure:


Directly on the configuration file: There are Dubbo related configuration files, here first write in, one will slowly introduce

<!--1. Configure Database Connection pool-->

<!--load configuration file-->

<context:property-placeholderlocation= "Classpath:properties/db.properties"/>

<!--database connection pool-->

<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource"

destroy-method= "Close" >

<property name= "url" value= "${jdbc.url}"/>

<propertyname= "username" value= "${jdbc.username}"/>

<propertyname= "Password" value= "${jdbc.password}"/>

<propertyname= "Driverclassname" value= "${jdbc.driver}"/>

<propertyname= "Maxactive" value= "ten"/>

<propertyname= "Minidle" value= "5"/>

</bean>

<!--2. Configure Sqlsessionfactory-->

<!--let Spring management sqlsessionfactory use--> in MyBatis and spring consolidation packages

<!--transaction manager-->

<beanid= "TransactionManager"

class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >

<!--data source-->

<propertyname= "DataSource" ref= "DataSource"/>

</bean>

<!--notice-->

<tx:adviceid= "Txadvice" transaction-manager= "TransactionManager" >

<tx:attributes>

--> of <!--communication behavior

<tx:methodname= "save*" propagation= "REQUIRED"/>

<tx:methodname= "insert*" propagation= "REQUIRED"/>

<tx:methodname= "add*" propagation= "REQUIRED"/>

<tx:methodname= "create*" propagation= "REQUIRED"/>

<tx:methodname= "delete*" propagation= "REQUIRED"/>

<tx:methodname= "update*" propagation= "REQUIRED"/>

<tx:methodname= "find*" propagation= "SUPPORTS" read-only= "true"/>

&nb

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.