(1)在Service层的main/resources目录中创建META-INF/spring目录,并将dubbo-provider.xml拷贝到此目录,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.xxx.yyy" />
<!--<import resource="classpath*:META-INF/META-INF/META-INF-dao.xml"/>-->
<!-- no leading classpath => servletResource -->
<dubbo:application name="xxx.yyy.provider"/>
<dubbo:protocol name="dubbo" port="20881" />
<dubbo:registry address="zookeeper://192.168.100.108:2181?backup=192.168.100.109:2181,192.168.100.110:2181" />
<dubbo:service interface="com.xxx.yyy.service.api.yyyService" ref="yyyService" />
</beans>
(2)在Service层main目录中创建conf目录,并将dubbo.properties拷贝到此目录,内容如下
##
# Copyright 1999-2011 Alibaba Group.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
dubbo.container=log4j,spring
dubbo.application.name=yyy-provider
dubbo.application.owner=silence
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://192.168.100.108:2181?backup=192.168.100.109:2181,192.168.100.110:2181
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
dubbo.monitor.protocol=registry
dubbo.protocol.name=dubbo
dubbo.protocol.port=20881
dubbo.service.loadbalance=roundrobin
dubbo.log4j.file=logs/dubbo-yyy-provider.log
dubbo.log4j.level=WARN
(3)在dao层main/resources目录中创建META-INF/spring目录,并将applicationContext-dao.xml拷贝到此目录,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2010 The myBatis Team Licensed under the Apache License, Version
2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License. -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
<context:property-placeholder location="classpath*:jdbc.properties" ignore-unresolvable="true" />
<!-- <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="driverClass" value="${jdbc.driverClassName}"></property>
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"></property>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
<property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
</bean>
-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.2.101:3306/mydb?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="priest"/>
<property name="password" value="priest"/>
</bean>
<!-- transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- enable component scanning (beware that this does not enable mapper
scanning!) -->
<!--SpringBean注入,自动扫描路径-->
<context:component-scan base-package="com.xxx.yyy" />
<!-- enable autowire -->
<context:annotation-config/>
<!-- enable transaction demarcation with annotations -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--要映射类的包路径,即POJO对象的路径-->
<property name="typeAliasesPackage" value="com.xxx.yyy.dao.model" />
<!--扫描mapper文件,否则如果Mapper接口文件改名的话,就会出现找不到对应的Mapper中方法的错误-->
<property name="mapperLocations" value="classpath*:com/xxx/yyy/mapper/*.xml"/>
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--扫描Mapper类并使它们自动装载-->
<property name="basePackage" value="com.xxx.yyy.mapper" />
</bean>
<bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper"></bean>
</beans>
(4)在service的pom.xml中加入
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
(5)在main下面创建assembly目录,并创建assembly.xml文件,内容如下
<assembly>
<id>assembly</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.parent.parent.basedir}/dubbo/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>src/main/conf</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
(6)用assembly打包工具,执行命令maven assembly:assembly进行打包(或者执行plugins中assembly:assembly)
(7)将包文件直接部署
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.xxx.yyy" />
<!--<import resource="classpath*:META-INF/META-INF/META-INF-dao.xml"/>-->
<!-- no leading classpath => servletResource -->
<dubbo:application name="xxx.yyy.provider"/>
<dubbo:protocol name="dubbo" port="20881" />
<dubbo:registry address="zookeeper://192.168.100.108:2181?backup=192.168.100.109:2181,192.168.100.110:2181" />
<dubbo:service interface="com.xxx.yyy.service.api.yyyService" ref="yyyService" />
</beans>
(2)在Service层main目录中创建conf目录,并将dubbo.properties拷贝到此目录,内容如下
##
# Copyright 1999-2011 Alibaba Group.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
dubbo.container=log4j,spring
dubbo.application.name=yyy-provider
dubbo.application.owner=silence
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://192.168.100.108:2181?backup=192.168.100.109:2181,192.168.100.110:2181
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
dubbo.monitor.protocol=registry
dubbo.protocol.name=dubbo
dubbo.protocol.port=20881
dubbo.service.loadbalance=roundrobin
dubbo.log4j.file=logs/dubbo-yyy-provider.log
dubbo.log4j.level=WARN
(3)在dao层main/resources目录中创建META-INF/spring目录,并将applicationContext-dao.xml拷贝到此目录,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2010 The myBatis Team Licensed under the Apache License, Version
2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License. -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
<context:property-placeholder location="classpath*:jdbc.properties" ignore-unresolvable="true" />
<!-- <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="driverClass" value="${jdbc.driverClassName}"></property>
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"></property>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
<property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
</bean>
-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.2.101:3306/mydb?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="priest"/>
<property name="password" value="priest"/>
</bean>
<!-- transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- enable component scanning (beware that this does not enable mapper
scanning!) -->
<!--SpringBean注入,自动扫描路径-->
<context:component-scan base-package="com.xxx.yyy" />
<!-- enable autowire -->
<context:annotation-config/>
<!-- enable transaction demarcation with annotations -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--要映射类的包路径,即POJO对象的路径-->
<property name="typeAliasesPackage" value="com.xxx.yyy.dao.model" />
<!--扫描mapper文件,否则如果Mapper接口文件改名的话,就会出现找不到对应的Mapper中方法的错误-->
<property name="mapperLocations" value="classpath*:com/xxx/yyy/mapper/*.xml"/>
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--扫描Mapper类并使它们自动装载-->
<property name="basePackage" value="com.xxx.yyy.mapper" />
</bean>
<bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper"></bean>
</beans>
(4)在service的pom.xml中加入
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
(5)在main下面创建assembly目录,并创建assembly.xml文件,内容如下
<assembly>
<id>assembly</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.parent.parent.basedir}/dubbo/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>src/main/conf</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
(6)用assembly打包工具,执行命令maven assembly:assembly进行打包(或者执行plugins中assembly:assembly)
(7)将包文件直接部署