dubbo 容器的加载内容可以扩展,内置了spring, jetty, log4j等加载,可通过Container扩展点进行扩展,参见:Container Spring Container 。
dubbo 容器自动加载META-INF/spring目录下的所有Spring配置。 所以spring 及dubbo 的相关配置要放在/META-INF/spring 目录下。
也可以在启动参数中配置:(配在java命令-D参数或者dubbo.properties中) dubbo.spring.config=classpath*:/META-INF/spring/*.xml ----配置spring配置加载位置。
打包配置如下:
<build>配置中指定了打包使用的 src/main/assembly/assembly.xml 配置文件:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</configuration>
</plugin>
<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>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<skip>true</skip>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.sh</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.bat</include>
</includes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<assembly>assembly.xml 配置文件指定了bin目录和打包后的jar 存放的位置lib目录。
<id>assembly</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/assembly/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
dubbo 服务工程目录结构如下:
使用maven 命令打包,打包后为tar 包,解压后,运行start.bat(start.sh。相关的脚本请到上传是资源中下载)即可启动dubbo 服务。如果要在本地测试,可以写一个main 方法,直接加载spring 及dubbo的相关配置即可启动dubbo的服务
测试工程说明:
dubbo-api dubbo 服务接口定义及数据传递的类的定义。定义了接口TicketApi和传递数据的类 TicketDTO。被dubbo-service 和 dubbo-test 依赖
dubbo-service dubbo 服务接口实现。maven打包的配置及assembly.xml 配置文件在这工程。包含了DubboServerMain ,直接加载spring 及dubbo 配置,对外提供服务,用于测试
dubbo-test 测试。直接加载配置文件, 订阅zookeeper 中提供的服务
工程使用 spring+dubbo+zookeeper ,把服务注册到zookeeper中,相关配置不再说明。
如上面工程打包后为:dubbo-service-1.0.0-assembly.tar.gz 文件,解压后有bin和lib 两个文件夹。bin中放的是脚本,lib 放的就是jar包。使用脚本启动(zookeeper 要启动),运行测试代码即可。
说明:
要把dubbo-api 工程install 到本地maven仓库,dubbo-service 、dubbo-test 才能编译通过。
assembly.xml 配置文件中有 STDOUT_FILE=$LOGS_DIR/stdout.log ,说明了日志文件的路径。 也指定了打包的文件格式tar.gz
工程源码:http://download.csdn.net/detail/convict_eva/9649331
参考:
http://zhaoshijie.iteye.com/blog/2214753
http://www.tuicool.com/articles/eE3mMzq