spring集成superdiamond

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013144287/article/details/77719629
spring集成superdiamond

       现在数据库使用superdiamond来进行统一管理的话会更加规范与操作方便,那么spring是怎么与superdiamond进行集成的呢?下面我们分享两种方式
一、首先我们看一下所用到的pom.xml
 <properties>
		<spring.version>3.2.4.RELEASE</spring.version>
		<mybatis.version>3.2.7</mybatis.version>
		<mybatis-spring.version>1.2.2</mybatis-spring.version>
		<logback.version>1.1.2</logback.version>
		<oracle.version>11.2.0.1.0</oracle.version>
		<slf4j.version>1.7.6</slf4j.version>
		<logback.version>1.1.2</logback.version>
  </properties>

 <dependencies>
      <!-- spring加mybatis加日志包 -->
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency> 
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.5</version> 
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId> 
            <version>${oracle.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId> 
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>${mybatis-spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version> 
        </dependency>
        <!-- superdiamond包 -->
        <dependency>
            <groupId>com.github.diamond</groupId>
            <artifactId>super-diamond-client</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <artifactId>jackson-mapper-asl</artifactId>
                    <groupId>org.codehaus.jackson</groupId>
                </exclusion>
            </exclusions>
        </dependency>
</dependencies>

二、anlyse-context.xml,不动态加载,spring直接加载
<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:redis="http://www.springframework.org/schema/redis"
	xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd
		http://www.springframework.org/schema/redis http://www.springframework.org/schema/redis/spring-redis-1.0.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
	
	<context:annotation-config />
    <context:component-scan base-package="com.starit.analyse" /> 
    
    <!-- superdiamond配置开始 -->
	<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
	    <property name="properties" ref="propertiesConfiguration" />
	</bean>
	
	<!-- superdiamond项目编码和profiles -->
	<bean id="propertiesConfiguration" class="com.github.diamond.client.PropertiesConfigurationFactoryBean">
	    <constructor-arg index="0" value="127.0.0.1" /><!-- superdiamond服务器地址 -->
            <constructor-arg index="1" value="9876" /> <!-- 端口号 -->
	    <constructor-arg index="2" value="ueap" /> <!-- 项目编码 -->
	    <constructor-arg index="3" value="test" /> <!-- profiles -->
	</bean>
	
	<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
	    <property name="driver" value="${jdbc.driverClass}"/>
	    <property name="driverUrl" value="${jdbc.url}"/>
	    <property name="user" value="${jdbc.username}"/>
	    <property name="password" value="${jdbc.password}" />
	    <property name="alias" value="Pool_dbname" />
	    <!-- proxool自动侦查各个连接状态的时间间隔(毫秒),侦查到空闲的连接就马上 回收,超时的销毁
	    	此处有bug注释掉,默认为30s
	    <property name="houseKeepingSleepTime" value="90000"/>
	     -->
	    <!--连接池中可用的连接数量.如果当前的连接池中的连接少于这个数值.新的连接将被建立 -->
	    <property name="prototypeCount" value="2" />
	    <!-- 最小与最大的连接数 -->
	    <property name="maximumConnectionCount" value="200" />
	    <property name="minimumConnectionCount" value="2" />
	    <!-- 可一次建立的最大连接数。那就是新增的连接请求,但还没有可供使用的连接,默认为10 -->
	    <property name="simultaneousBuildThrottle" value="10" />
	    <!-- 连接最长时间(默认为4个小时) 此处有bug,不能设置为int类型
	    <property name="maximumConnectionLifetime" value="14400000" />
	    -->
	    <!-- 验证连接的sql -->
	    <property name="houseKeepingTestSql" value="select CURRENT_DATE from DUAL" />
	    <!-- 使用连接之前验证 -->
	    <property name="testBeforeUse" value="true"></property>
	    <!-- 日志级别 -->
	    <property name="statisticsLogLevel" value="INFO"></property>
	    <property name="trace" value="true"></property>
	</bean>
	 <!-- superdiamond配置结束 -->
	
	<bean class="com.starit.analyse.executor.AnalyseExecutor">
		<constructor-arg index="0" value="10"/>
	</bean>

	<import resource="scheduleContext.xml" />	
</beans>
三、anlyse-context.xml在运行时动态加载,配置VM参数
<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:redis="http://www.springframework.org/schema/redis"
	xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd
		http://www.springframework.org/schema/redis http://www.springframework.org/schema/redis/spring-redis-1.0.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
	
	<context:annotation-config />
    <context:component-scan base-package="com.starit.analyse" /> 
    
    <!-- superdiamond配置开始 -->
	<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
	    <property name="properties" ref="propertiesConfiguration" />
	</bean>
	
	<!-- superdiamond项目编码和profiles -->
	<bean id="propertiesConfiguration" class="com.github.diamond.client.PropertiesConfigurationFactoryBean">
	    <constructor-arg index="0" value="ueap" /> <!-- 项目编码 -->
	    <constructor-arg index="1" value="test" /> <!-- profiles -->
	</bean>
	
	<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
	    <property name="driver" value="${jdbc.driverClass}"/>
	    <property name="driverUrl" value="${jdbc.url}"/>
	    <property name="user" value="${jdbc.username}"/>
	    <property name="password" value="${jdbc.password}" />
	    <property name="alias" value="Pool_dbname" />
	    <!-- proxool自动侦查各个连接状态的时间间隔(毫秒),侦查到空闲的连接就马上 回收,超时的销毁
	    	此处有bug注释掉,默认为30s
	    <property name="houseKeepingSleepTime" value="90000"/>
	     -->
	    <!--连接池中可用的连接数量.如果当前的连接池中的连接少于这个数值.新的连接将被建立 -->
	    <property name="prototypeCount" value="2" />
	    <!-- 最小与最大的连接数 -->
	    <property name="maximumConnectionCount" value="200" />
	    <property name="minimumConnectionCount" value="2" />
	    <!-- 可一次建立的最大连接数。那就是新增的连接请求,但还没有可供使用的连接,默认为10 -->
	    <property name="simultaneousBuildThrottle" value="10" />
	    <!-- 连接最长时间(默认为4个小时) 此处有bug,不能设置为int类型
	    <property name="maximumConnectionLifetime" value="14400000" />
	    -->
	    <!-- 验证连接的sql -->
	    <property name="houseKeepingTestSql" value="select CURRENT_DATE from DUAL" />
	    <!-- 使用连接之前验证 -->
	    <property name="testBeforeUse" value="true"></property>
	    <!-- 日志级别 -->
	    <property name="statisticsLogLevel" value="INFO"></property>
	    <property name="trace" value="true"></property>
	</bean>
	 <!-- superdiamond配置结束 -->
	
	<bean class="com.starit.analyse.executor.AnalyseExecutor">
		<constructor-arg index="0" value="10"/>
	</bean>

	<import resource="scheduleContext.xml" />	
</beans>
shell脚本配置vm参数,配置处是:
SUPERDIAMOND="-Dspuerdiamond.host=127.0.0.1 -Dspuerdiamond.port=9876"
shell脚本是:
#!/bin/bash

#JAVA_HOME="/usr/java/jdk1.6.0_33"

if [ "$JAVA_HOME" != "" ]; then
  #echo "run java in $JAVA_HOME"
  JAVA_HOME=$JAVA_HOME
fi

if [ "$JAVA_HOME" = "" ]; then
  echo "Error: JAVA_HOME is not set."
  exit 1
fi

JAVA=$JAVA_HOME/bin/java
BASE_HOME=$BASE_DIR
BASE_NAME="CollectMaster"

#Ueap JMX port
export JMX_PORT=8222
#export CLASSPATH=$BASE_DIR/conf:$(ls $BASE_DIR/lib/*.jar | tr '\n' :)
export CLASSPATH=$BASE_DIR/conf:$BASE_DIR/lib/*:$BASE_DIR/plugins/*

#UEAP jvm args
JMX_ARGS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=$JMX_PORT"
SUPERDIAMOND="-Dspuerdiamond.host=127.0.0.1 -Dspuerdiamond.port=9876"
BASE_JVM_ARGS="-Xmx2048m -Xms1024m"
BASE_APP_ARGS="-cp $CLASSPATH"
APP_JVM_ARGS="$BASE_JVM_ARGS  -Dcollect.start.worker=false $JMX_ARGS $SUPERDIAMOND"




阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页