SpringCloud 项目实例

基于springboot, 使用eureka, zuul, feign等搭建一个可用的springCloud项目, 项目为基于maven主从项目

一. parent 配置如下:

  1. parent目录如下: 输入图片说明

  2. parent pom.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<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.xxxx.xxxx</groupId>
	<artifactId>*parent</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>

	<modules>
		<module>*backstage-server</module>
		<module>*computing-engin</module>
		<module>*control-server</module>
		<module>*cloud-eureka</module>
       </modules>

	<!-- 使用最新的spring-boot版本 -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.0.RELEASE</version>
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
		<!-- jackson 版本 -->
		<jackson.version>2.8.1</jackson.version>
	</properties>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Brixton.SR5</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>

			<dependency>
				<groupId>org.mybatis.spring.boot</groupId>
				<artifactId>mybatis-spring-boot-starter</artifactId>
				<version>1.2.0</version>
			</dependency>
			<!--生产环境可去掉-->
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-devtools</artifactId>
				<optional>true</optional>
			</dependency>

			<!-- jackson -->
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-core</artifactId>
				<version>${jackson.version}</version>
			</dependency>
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-databind</artifactId>
				<version>${jackson.version}</version>
			</dependency>
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-annotations</artifactId>
				<version>${jackson.version}</version>
			</dependency>

			<!-- oracle驱动包 -->
			<dependency>
				<groupId>com.oracle</groupId>
				<artifactId>ojdbc6</artifactId>
				<version>11.2.0.1.0</version>
			</dependency>
			<!-- 分页包 -->
			<dependency>
				<groupId>com.github.pagehelper</groupId>
				<artifactId>pagehelper</artifactId>
				<version>5.0.0</version>
			</dependency>

		</dependencies>
	</dependencyManagement>
	
       <!--支持热加载-->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

	<!-- maven发布仓库 -->
	<!-- <distributionManagement> -->
	<!-- <repository> -->
	<!-- <uniqueVersion>false</uniqueVersion> -->
	<!-- <id>corp1</id> -->
	<!-- <name>Corporate Repository</name> -->
	<!-- <url>scp://repo/maven2</url> -->
	<!-- <layout>default</layout> -->
	<!-- </repository> -->
	<!-- </distributionManagement> -->

	<!-- 仓库地址 -->
	<!-- <repository> -->
	<!-- <id>nexus</id> -->
	<!-- <name>local private nexus</name> -->
	<!-- <url>http://maven.oschina.net/content/groups/public/</url> -->
	<!-- <releases> -->
	<!-- <enabled>true</enabled> -->
	<!-- </releases> -->
	<!-- <snapshots> -->
	<!-- <enabled>false</enabled> -->
	<!-- </snapshots> -->
	<!-- </repository> -->
</project>

二. 单独的控制台backstage-server

  1. 项目结构 --war 可单独部署

输入图片说明

  1. pom.xml

<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.xxxx.xxxx</groupId>
		<artifactId>cloud-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>rbackstage-server</artifactId>
	<name>backstage-server</name>
	<packaging>war</packaging>
	<url>http://maven.apache.org</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<!-- spring-boot的web启动的jar包 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<!--<scope>provided</scope>-->
		</dependency>

		<!-- jackson -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.27</version>
		</dependency>

		<!-- 注册服务 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>

		<!-- API GateWay Zuul -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zuul</artifactId>
		</dependency>

		<!-- 断路器 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix</artifactId>
		</dependency>

		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.3.1</version>
		</dependency>

		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-autoconfigure</artifactId>
			<version>1.2.0</version>
		</dependency>

		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.4.2</version>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>

		<!-- oracle驱动包 -->
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc6</artifactId>
		</dependency>
		<!-- 分页包 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper-spring-boot-starter</artifactId>
			<version>1.1.0</version>
		</dependency>

		<!-- swagger-ui -->
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.2.2</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.2.2</version>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<!--<scope>test</scope>-->
		</dependency>

		<dependency>
			<groupId>com.ups.util</groupId>
			<artifactId>ups_util</artifactId>
			<version>1.0.0</version>
		</dependency>

		<dependency>
			<groupId>com.novell.ldap</groupId>
			<artifactId>jldap_local</artifactId>
			<version>4.3</version>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-cache</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-redis</artifactId>
		</dependency>

		<!-- <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> 
			</dependency> -->

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
		</dependency>

		<dependency>
			<groupId>com.github.ulisesbocchio</groupId>
			<artifactId>jasypt-spring-boot-starter</artifactId>
			<version>1.9</version>
		</dependency>

		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.15</version>
		</dependency>
		
		
		<dependency>
			<groupId>json-lib</groupId>
			<artifactId>json-lib</artifactId>
			<version>2.4-jdk15</version>
			<type>jar</type>
		</dependency>
		
		<dependency>
			<groupId>httpmime</groupId>
			<artifactId>httpmime</artifactId>
			<version>4.5.2</version>
			<type>jar</type>
		</dependency>
		
		<dependency>
			<groupId>ezmorph</groupId>
			<artifactId>ezmorph</artifactId>
			<version>1.0.6</version>
			<type>jar</type>
		</dependency>
		
		<dependency>
			<groupId>commons-beanutils</groupId>
			<artifactId>commons-beanutils</artifactId>
			<type>jar</type>
		</dependency>
		
	</dependencies>

		


	<profiles>
		<profile>
			<!-- 测试环境 -->
			<id>beta</id>
			<properties>
				<profiles.active>beta</profiles.active>
			</properties>
			
			<activation>
				<!-- 设置默认激活这个配置 -->
				<activeByDefault>true</activeByDefault>
			</activation>
			
		</profile>
		<profile>
			<!-- 发布环境 -->
			<id>release</id>
			<properties>
				<profiles.active>release</profiles.active>
			</properties>
		</profile>

	</profiles>

	<build>
		<!-- 打包的包名 -->
		<finalName>backstage-server</finalName>
		<!-- 定义了变量配置文件的地址 -->
		<filters>
			<filter>src/main/resources/config/config-${profiles.active}.properties</filter>
		</filters>
		<resources>
			<resource>
				<directory>src/main/resources/</directory>
				<filtering>true</filtering>
				<includes>
					<include>static/host.properties</include>
					<include>dataSource.properties</include>
					<include>application.properties</include>
				</includes>
			</resource>
			<resource>
				<directory>src/main/resources/</directory>
				<filtering>false</filtering>
				<excludes>
					<exclude>config/*</exclude>
				</excludes>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
			</plugin>

			<!-- <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> 
				<version>1.3.5</version> <dependencies> <dependency> <groupId>com.oracle</groupId> 
				<artifactId>ojdbc6</artifactId> <version>11.2.0.1.0</version> </dependency> 
				<dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> 
				<version>1.3.5</version> </dependency> </dependencies> <executions> <execution> 
				<id>Generate MyBatis Artifacts</id> <phase>package</phase> <goals> <goal>generate</goal> 
				</goals> </execution> </executions> <configuration> 允许移动生成的文件 <verbose>true</verbose> 
				是否覆盖 <overwrite>false</overwrite> 自动生成的配置 <configurationFile> src/main/resources/mybatis-generator_.xml</configurationFile> 
				</configuration> </plugin> -->

		</plugins>
	</build>

</project>

  1. App启动类配置

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@ServletComponentScan
//@EnableRedisHttpSession
@EnableTransactionManagement
public class RiskBackstageServerApp extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    	return application.sources(RiskBackstageServerApp.class);
    }

	public static void main(String[] args) {
		SpringApplication.run(RiskBackstageServerApp.class, args);
	}
}

  1. mybatis-generator.xml配置

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE generatorConfiguration  
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
	<!-- 项目 右键 》run as 》 maven bulid 》弹出对话框 在goals中输入mybatis-generator:generate 
		》 点击 Run -->
	<context id="DB2Tables" targetRuntime="MyBatis3">
		<commentGenerator>
			<property name="suppressDate" value="true" />
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!--数据库链接地址账号密码 -->
		<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
			connectionURL="jdbc:oracle:thin:@xx.xx.xx.xx:1521:orcl" userId="xxxx"
			password="xxxxxxx">
		</jdbcConnection>
		<javaTypeResolver>
			<property name="forceBigDecimals" value="true" />
		</javaTypeResolver>
		<!--生成Model类存放位置 -->
		<javaModelGenerator targetPackage="com.cjhx.risk.backstage.quota.common.domain"
			targetProject="src/main/java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<!--生成映射文件存放位置 -->
		<sqlMapGenerator targetPackage="mappers"
			targetProject="src/main/resources">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>
		<!--生成Dao类存放位置 -->
		<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码 type="ANNOTATEDMAPPER",生成Java Model 
			和基于注解的Mapper对象 type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象 type="XMLMAPPER",生成SQLMap 
			XML文件和独立的Mapper接口 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="com.cjhx.risk.backstage.quota.common.dao" targetProject="src/main/java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>
		<!--生成对应表及类名 -->
		<table tableName="rc_onscan_rule_item_status" domainObjectName="RcOnscanRuleItemStatus"
			enableCountByExample="false" enableUpdateByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			selectByExampleQueryId="false">
		</table>
	</context>
</generatorConfiguration>
  1. logback-spring.xml 日志文件配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="false" scanPeriod="10 seconds">

	<!-- scan: -->
	<!-- 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。(这个功能可以在不重启运行环境下,调整打印日志的细节,方便定位问题) -->
	<!-- scanPeriod: -->
	<!-- 设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
	<!-- debug: -->
	<!-- 当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
	<!-- Logger 可以被分配级别。级别包括:TRACE、DEBUG、INFO、WARN 和 ERROR -->
	<!-- 级别排序为: TRACE < DEBUG < INFO < WARN < ERROR -->
	<!-- logger:日志所处的包 -->
	<!-- level:日志打印级别 -->

	<!-- <logger name="org.springframework" level="WARN" /> -->
	<!-- <logger name="org.apache.activemq" level="INFO" /> -->
	<!-- <logger name="org.apache.zookeeper" level="INFO" /> -->
	<!-- com.alibaba.dubbo是dubbo服务的包,在如何是info一下的级别会产生大量的启动日志,调成WARN减少日志输出 -->
	<!-- <logger name="com.alibaba.dubbo" level="WARN" /> -->
	<!-- com.ztev.audit.dao是本项目的dao层的包,把这个包的打印日志级别调成 DEBUG级别可以看到sql执行 -->
	<!-- <logger name="com.ztev.audit.dao" level="DEBUG" /> -->
	<!-- <logger name="com.ztev.cardNoVin.dao" level="DEBUG" /> -->

	<!--文件输出的格式设置 -->
	<appender name="FILE"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<!-- 日志日常打印文件 -->
		<file>/app/applogs/riskapp/riskapp.log</file>
		<!-- 文件输出的日志 的格式 -->
		<encoder>
			<pattern>
				%date{yyyy-MM-dd HH:mm:ss} %-5level %-4line --- %logger{96}  : %msg%n
			</pattern>
			<charset>UTF-8</charset> <!-- 此处设置字符集,防止中文乱码 -->
		</encoder>
		<!-- 样例: -->
		<!-- [ INFO ] [2017-06-09 15:15:59] org.apache.tomcat.util.net.NioSelectorPool 
			[179] - Using a shared selector for servlet -->
		<!-- [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] %msg%n -->
		<!-- level日志级别 时间 打印日志所处包.类 出现代码行 日志信息 -->

		<!-- 配置日志所生成的目录以及生成文件名的规则 在logs/mylog-2017-06-31.0.log -->
		<!-- ch.qos.logback.core.rolling.TimeBasedRollingPolicy -->
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>/app/applogs/riskapp/riskapp-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
			<!--文件达到 最大xxMB时会被切割 -->
			<maxFileSize>20MB</maxFileSize>
			<!-- 如果按天来回滚,则最大保存时间为365天,365天之前的都将被清理掉 -->
			<maxHistory>33</maxHistory>
			<!-- 日志总保存量为10GB -->
			<totalSizeCap>3GB</totalSizeCap>
<!-- 			<timeBasedFileNamingAndTriggeringPolicy -->
<!-- 				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> -->
<!-- 				<maxFileSize>1MB</maxFileSize> -->
<!-- 			</timeBasedFileNamingAndTriggeringPolicy> -->
		</rollingPolicy>
		
		<!-- <filter>: -->
		<!-- 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NEUTRAL,ACCEPT其中之一。返回DENY,日志将立即被抛弃不再经过其他过滤器;返回NEUTRAL,有序列表里的下个过滤器过接着处理日志;返回ACCEPT,日志会被立即处理,不再经过剩余过滤器。 -->
		<!-- 过滤器被添加到<appender> 中,为<appender> 添加一个或多个过滤器后,可以用任意条件对日志进行过滤。<appender> 
			有多个过滤器时,按照配置顺序执行。 -->
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>DEBUG</level>
		</filter>

		<!-- Safely log to the same file from multiple JVMs. Degrades performance! -->
		<!-- <prudent>:如果是 true,日志会被安全的写入文件,即使其他的FileAppender也在向此文件做写入操作,效率低,默认是 
			false。 -->
		<prudent>false</prudent>
	</appender>

	<!--控制台输出的格式设置 -->
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<!-- 控制台输出的日志 的格式 -->
		<encoder>
			<pattern>
				%date{yyyy-MM-dd HH:mm:ss} %-5level %-4line --- %logger{96}  : %msg%n
			</pattern>
			<charset>UTF-8</charset> <!-- 此处设置字符集 -->
		</encoder>
		<!-- 只是DEBUG级别以上的日志才显示 -->
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>DEBUG</level>
		</filter>
	</appender>

	<!-- root: -->
	<!-- 也是<loger>元素,但是它是根loger。只有一个level属性,应为已经被命名为"root". -->
	<!-- level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,不能设置为INHERITED或者同义词NULL。默认是DEBUG。 -->
	<root level="DEBUG">
		<appender-ref ref="FILE" />
		<appender-ref ref="STDOUT" />
	</root>
</configuration>
  1. dataSource.properties 配置

#风控系统数据源
spring.datasource.risk.driver-class-name=oracle.jdbc.driver.OracleDriver
#spring.datasource.risk.url=jdbc:oracle:thin:@xx.xx.xx.xx:1521:orcl
spring.datasource.risk.url=@spring.datasource.risk.url@
#spring.datasource.risk.username=xxx
spring.datasource.risk.username=@spring.datasource.risk.username@
#spring.datasource.risk.password=xxx
spring.datasource.risk.password=@spring.datasource.risk.password@
spring.datasource.risk.validation-query=select 1 from dual
spring.datasource.risk.test-while-idle=true
spring.datasource.risk.test-on-borrow=true
spring.datasource.risk.time-between-eviction-runs-millis=18000

#prod数据源
spring.datasource.prod.driver-class-name=oracle.jdbc.driver.OracleDriver
#spring.datasource.prod.url=jdbc:oracle:thin:@xx.xx.xx.xx:10521:prod
spring.datasource.prod.url=@spring.datasource.prod.url@
#spring.datasource.prod.username=xxx
spring.datasource.prod.username=@spring.datasource.prod.username@
#spring.datasource.prod.password=xxx
spring.datasource.prod.password=@spring.datasource.prod.password@
spring.datasource.prod.validation-query=select 1 from dual
spring.datasource.prod.test-while-idle=true
spring.datasource.prod.test-on-borrow=true
spring.datasource.prod.time-between-eviction-runs-millis=18000

#warehouse数据源
spring.datasource.warehouse.driver-class-name=oracle.jdbc.driver.OracleDriver
#spring.datasource.prod.url=jdbc:oracle:thin:@xx.xx.xx.xx:10521:prod
spring.datasource.warehouse.url=@spring.datasource.warehouse.url@
#spring.datasource.prod.username=xxx
spring.datasource.warehouse.username=@spring.datasource.warehouse.username@
#spring.datasource.prod.password=xxx
spring.datasource.warehouse.password=@spring.datasource.warehouse.password@
spring.datasource.warehouse.validation-query=select 1 from dual
spring.datasource.warehouse.test-while-idle=true
spring.datasource.warehouse.test-on-borrow=true
spring.datasource.warehouse.time-between-eviction-runs-millis=18000


  1. application.properties 配置
server.port=8086
spring.application.name=backstage-server

#spring.redis.host=xx.xx.xx.xx
#spring.redis.port=6379
#spring.redis.pool.max-idle=8
#spring.redis.pool.min-idle=1
#spring.redis.pool.max-active=8
#spring.redis.pool.max-wait=-1

#不写http://前缀可能会报错
#spring.cloud.config.uri=http://localhost:8088
#spring.cloud.config.name=cloud-config
#spring.cloud.config.profile=dev

#eureka服务注册地址
#eureka.client.serviceUrl.defaultZone=http\://localhost\:8761/eureka/

# session timeout in seconds
server.session-timeout=@server.session-timeout@

#加密因子
#jasypt.encryptor.password=123456
jasypt.encryptor.password=@jasypt.encryptor.password@

#AD域管理员用户名
#ldap.ad.username=admin
ldap.ad.username=@ldap.ad.username@

#AD域管理员密码
#ldap.ad.password=TyRzlqZOJXQg0GFkS7byCg==
ldap.ad.password=@ldap.ad.password@


#pagehelper.
pagehelper.autoDialect=true
pagehelper.closeConn=true

#converters 默认jackson
spring.http.converters.preferred-json-mapper=jackson

mybatis.type-aliases-package=
mybatis.type-handlers-package=
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=30
#mybatis.mapper-locations:classpath*:mappers/*Mapper.xml

#日志
logging.file=@logging.file@
#logging.level.root=DEBUG
logging.level.root=@logging.level.root@
logging.level.com.cjhx.risk=debug
logging.level.sample.mybatis.mapper=TRACE

#发送邮件和短信同异步标志:0同步,1异步
fkyq.post.inspection.config.syncFlag=1
#邮件反馈异步超时更新时间
fkyq.post.inspection.config.mail.time.out.update.hour=0.1
#短信反馈异步超时更新时间
fkyq.post.inspection.config.sms.time.out.update.hour=0.2

#接口调用人
fkyq.post.inspection.config.fromUser=cjhx
#接口调用系统
fkyq.post.inspection.config.fromSystem=fkyq
#接口调用系统ID
fkyq.post.inspection.config.fromSystemUid=fkyq
#短信回调接口
#fkyq.post.inspection.config.smsCallBackUrl=@fkyq.post.inspection.config.smsCallBackUrl@
#邮件回调接口
#fkyq.post.inspection.config.mailCallBackUrl=@fkyq.post.inspection.config.mailCallBackUrl@
#
fkyq.post.inspection.config.syncSendMailUrl=http://xx.xx.xx.xx:8080/msnc/interface/email/sendMail
fkyq.post.inspection.config.asyncSendMailUrl=http://xx.xx.xx.xx:8080/msnc/interface/email/asyncSendMail
fkyq.post.inspection.config.syncEqualContentUrl=http://xx.xx.xx.xx:8080/msnc/interface/mobile/sendEqualContent
fkyq.post.inspection.config.asyncEqualContentUrl=http://xx.xx.xx.xx:8080/msnc/interface/mobile/sendAsyncEqualContent
fkyq.post.inspection.config.syncNotEqualContentUrl=http://xx.xx.xx.xx:8080/msnc/interface/mobile/sendNotEqualContent
fkyq.post.inspection.config.asyncNotEqualContentUrl=http://xx.xx.xx.xx:8080/msnc/interface/mobile/sendAsyncNotEqualContent
fkyq.post.inspection.config.smsCallBackUrl=http://xx.xx.xx.xx8086/servlet/sms
fkyq.post.inspection.config.mailCallBackUrl=http://xx.xx.xx.xx:8086/servlet/mail


  1. config *

输入图片说明

config-beta.properties

jasypt.encryptor.password=123456
spring.datasource.risk.url=jdbc:oracle:thin:@xx.xx.xx.xx:1521:orcl
spring.datasource.risk.username=xxx
spring.datasource.risk.password=xxxx
spring.datasource.prod.url=jdbc:oracle:thin:@xx.xx.xx.xx:10521:prod
spring.datasource.prod.username=xxx
spring.datasource.prod.password=xxxx
#spring.datasource.prod.username=xxx
#spring.datasource.prod.password=xxxx
spring.datasource.warehouse.url=jdbc:oracle:thin:@xx.xx.xx.xx:1521:orcl
spring.datasource.warehouse.username=xxxx
spring.datasource.warehouse.password=xxxx
ldap.ad.username=admin
ldap.ad.password=TyRzlqZOJXQg0GFkS7byCg==
ldap.ad.ipaddress=10.201.200.28
ldap.ad.ipport=389
ldap.ad.DNEnCode=true
ldap.ad.userDN=OU=\u529e\u516c\u7ba1\u7406,DC=CJHX,DC=TEST
ldap.ad.dimissionDN=OU=\u79bb\u804c\u5458\u5de5,OU=\u529e\u516c\u7ba1\u7406,DC=CJHX,DC=TEST
#
#fkyq.post.inspection.config.syncSendMailUrl=http://xx.xx.xx.xx:8080/msnc/interface/email/sendMail
#fkyq.post.inspection.config.asyncSendMailUrl=http://xx.xx.xx.xx:8080/msnc/interface/email/asyncSendMail
#fkyq.post.inspection.config.syncEqualContentUrl=http://xx.xx.xx.xx:8080/msnc/interface/mobile/sendEqualContent
#fkyq.post.inspection.config.asyncEqualContentUrl=http://xx.xx.xx.xx:8080/msnc/interface/mobile/sendAsyncEqualContent
#fkyq.post.inspection.config.syncNotEqualContentUrl=http://xx.xx.xx.xx:8080/msnc/interface/mobile/sendNotEqualContent
#fkyq.post.inspection.config.asyncNotEqualContentUrl=http://xx.xx.xx.xx:8080/msnc/interface/mobile/sendAsyncNotEqualContent
#fkyq.post.inspection.config.smsCallBackUrl=http://xx.xx.xx.xx:8086/servlet/sms
#fkyq.post.inspection.config.mailCallBackUrl=http://xx.xx.xx.xx:8086/servlet/mail
#
logging.level.root=info
logging.file=/app/applogs/riskapp/riskapp.log
server.session-timeout=1200

9.数据库Java配置类

输入图片说明

  1. datasourceConfig

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;


@Configuration
@PropertySource("classpath:dataSource.properties")
@MapperScan(sqlSessionFactoryRef = "prodSqlSessionFactory", basePackages = "com.xx.xx.xx.*.dao")
public class DatasourceConfig {
	
	@Bean(name = "prodDataSource")
	@ConfigurationProperties(prefix = "spring.datasource.prod")
	public DataSource riskDataSource() 
	{
		return DataSourceBuilder.create().build();
	}

	@Bean(name = "prodSqlSessionFactory")
	public SqlSessionFactory riskSqlSessionFactory(@Qualifier("prodDataSource") DataSource dataSource)throws Exception
	{
		SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
		bean.setDataSource(dataSource);
		Resource[] resources=new PathMatchingResourcePatternResolver().getResources("classpath*:o32mappers/*Mapper.xml");
		bean.setMapperLocations(resources);
		return bean.getObject();
	}

	@Bean(name = "prodTransactionManager")
	public DataSourceTransactionManager riskTransactionManager(@Qualifier("prodDataSource") DataSource dataSource) 
	{
		return new DataSourceTransactionManager(dataSource);
	}

}
  1. Page

public class Page {
	/*
	 * 当前页数
	 */
	private int currentPage = 1;
	/*
	 * 每页展示记录数
	 */
	private int perpageCounts = 10;
	/*
	 * 总记录数
	 */
	private int totalCounts = 0;

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		if (currentPage > 0) {
			this.currentPage = currentPage;
		}
	}

	public int getPerpageCounts() {
		return perpageCounts;
	}

	public void setPerpageCounts(int perpageCounts) {
		if (perpageCounts > 0) {
			this.perpageCounts = perpageCounts;
		}
	}

	public int getTotalCounts() {
		return totalCounts;
	}

	public void setTotalCounts(int totalCounts) {
		this.totalCounts = totalCounts;
	}

}
  1. PageHelperConfig
import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.pagehelper.PageHelper;

/** 注册MyBatis分页插件PageHelper */
@Configuration
public class PageHelperConfig {
	@Bean
	public PageHelper pageHelper() {
		PageHelper pageHelper = new PageHelper();
		Properties p = new Properties();
		p.setProperty("offsetAsPageNum", "true");
		p.setProperty("rowBoundsWithCount", "true");
		p.setProperty("reasonable", "true");
		//p.setProperty("autoRuntimeDialect", "true");
		pageHelper.setProperties(p);
		return pageHelper;
	}
}
  1. PageResult

import java.util.List;

public class PageResult<T> {
	public List<T> list;
	public Page page;
	public int flag;
	
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	
}
  1. RedisCacheConfig
import java.lang.reflect.Method;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;


//@Configuration  
//@EnableCaching
public class RedisCacheConfig extends CachingConfigurerSupport {
	
    @Bean  
    public KeyGenerator wiselyKeyGenerator(){  
        return new KeyGenerator() {  
            @Override  
            public Object generate(Object target, Method method, Object... params) {  
                StringBuilder sb = new StringBuilder();  
                sb.append(target.getClass().getName());  
                sb.append(method.getName());  
                for (Object obj : params) {  
                    sb.append(obj.toString());  
                }  
                return sb.toString();  
            }  
        };    
    }
    
    @Bean  
    public CacheManager cacheManager(  
            @SuppressWarnings("rawtypes") RedisTemplate redisTemplate) {  
        return new RedisCacheManager(redisTemplate);  
    }
    
    @Bean  
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {  
        StringRedisTemplate template = new StringRedisTemplate(factory);  
        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);  
        ObjectMapper om = new ObjectMapper();  
        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);  
        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);  
        jackson2JsonRedisSerializer.setObjectMapper(om);  
        template.setValueSerializer(jackson2JsonRedisSerializer);  
        template.afterPropertiesSet();  
        return template;  
    }
}

  1. Swagger2
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2 {

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage("com.cjhx.risk")).paths(PathSelectors.any()).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("Swagger2 RESTful APIs").description("API文档")
				.contact("risk_last").version("1.0").build();
	}

}

  1. WebAppAdapterConfig

i``` mport org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.cjhx.risk.configs.interceptor.AuthorizationInteceptor; @Configuration public class WebAppAdapterConfig extends WebMvcConfigurerAdapter { private static Logger logger = LoggerFactory.getLogger(WebAppAdapterConfig.class);

//授权检查拦截器
@Autowired
private AuthorizationInteceptor authorization;

/* 公共过滤不做拦截的path表达式 */
String[] excludeCommonPattern = new String[]{"/","/**/login/**", "/**/logout/**", "/**/errors/**","/**/password**"};

@Override
public void addInterceptors(InterceptorRegistry registry) {
	super.addInterceptors(registry);
	registry.addInterceptor(authorization).addPathPatterns("/**").excludePathPatterns(excludeCommonPattern);
	logger.info("授权检查拦截器注册成功");
}

}


三. eureka 注册中心

1. pom.xml 

<?xml version="1.0"?>

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.xxxx.xxxx</groupId> <artifactId>cloud-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>cloud-eureka</artifactId> <name>cloud-eureka</name> <packaging>war</packaging> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- spring-boot的web启动的jar包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>

	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-eureka-server</artifactId>
	</dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-actuator</artifactId>
	</dependency>

	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>

<profiles>
	<profile>
		<!-- 测试环境 -->
		<id>beta</id>
		<properties>
			<profiles.active>beta</profiles.active>
		</properties>
		
		<activation>
			<!-- 设置默认激活这个配置 -->
			<activeByDefault>true</activeByDefault>
		</activation>
		
	</profile>
	<profile>
		<!-- 发布环境 -->
		<id>release</id>
		<properties>
			<profiles.active>release</profiles.active>
		</properties>
	</profile>
</profiles>

<build>
	<!-- 打包的包名 -->
	<finalName>*eureka</finalName>
	<filters>
		<filter>src/main/resources/config/config-${profiles.active}.properties</filter>
	</filters>
	<resources>
		<resource>
			<directory>src/main/resources</directory>
			<filtering>true</filtering>
			<excludes>
				<exclude>config/*</exclude>
			</excludes>
		</resource>
	</resources>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-war-plugin</artifactId>
		</plugin>
	</plugins>
</build>

</project> ```

  1. application.properties
server.port=8762
eureka.instance.preferIpAddress=true
eureka.instance.hostname=risk-cloud-eureka
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false

#设为false,关闭自我保护主要
eureka.server.enable-self-preservation=false
#清理间隔(单位毫秒,默认是60*1000)
eureka.server.eviction-interval-timer-in-ms=4000

#eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
#eureka.client.serviceUrl.defaultZone=http\://xx.xx.xx.xx\:8762/eureka/
eureka.client.serviceUrl.defaultZone=@eureka.client.serviceUrl.defaultZone@

#日志
logging.file=@logging.file@
#logging.level.root=DEBUG
logging.level.root=@logging.level.root@
  1. config-beta.properties
eureka.client.serviceUrl.defaultZone=http\://localhost\:8762/eureka/
logging.level.root=info
logging.file=/app/applogs/eureka/eureka.log
  1. App 启动类
package com.cjhx.risk.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class App extends SpringBootServletInitializer {

	@Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    	return application.sources(App.class);
    }

	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

四. gateway

  1. pom.xml
<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>xxx</groupId>
		<artifactId>parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>control-server</artifactId>
	<name>control-server</name>
	<packaging>war</packaging>
	<url>http://maven.apache.org</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<!-- spring-boot的web启动的jar包 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<!-- 注册服务 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>

		<!-- API GateWay Zuul -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zuul</artifactId>
		</dependency>

		<!-- 断路器 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix</artifactId>
		</dependency>

		<!-- json包 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.1.25</version>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<profiles>
		<profile>
			<!-- 测试环境 -->
			<id>beta</id>
			<properties>
				<profiles.active>beta</profiles.active>
			</properties>
			
			<activation>
				<!-- 设置默认激活这个配置 -->
				<activeByDefault>true</activeByDefault>
			</activation>
			
		</profile>
		<profile>
			<!-- 发布环境 -->
			<id>release</id>
			<properties>
				<profiles.active>release</profiles.active>
			</properties>
		</profile>
	</profiles>

	<build>
		<!-- 打包的包名 -->
		<finalName>riskgateway</finalName>
		<filters>
			<filter>src/main/resources/config/config-${profiles.active}.properties</filter>
		</filters>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<excludes>
					<exclude>config/*</exclude>
				</excludes>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

  1. application.properties
server.port=8080
spring.application.name=control-server

#不写http://前缀可能会报错
#spring.cloud.config.uri=http://localhost:8888
#spring.cloud.config.name=cloud-config
#spring.cloud.config.profile=dev

#ribbon.eureka.enabled=false

hystrix.command.default.execution.timeout.enabled=false

#eureka服务注册地址
#eureka.client.serviceUrl.defaultZone=http\://localhost\:8761/eureka/
eureka.client.serviceUrl.defaultZone=@eureka.client.serviceUrl.defaultZone@

zuul.routes.CheckRisk.path=/RiskControl/CheckRisk/0.0.1/Accounts/**
zuul.routes.CheckRisk.stripPrefix=false
zuul.routes.CheckRisk.serviceId=risk-computing-engin

zuul.routes.TryRisk.path=/RiskControl/TryRisk/0.0.1/Accounts/**
zuul.routes.TryRisk.stripPrefix=false
zuul.routes.TryRisk.serviceId=risk-computing-engin

zuul.routes.RiskQuery.path=/RiskControl/RiskQuery/0.0.1/Accounts/**
zuul.routes.RiskQuery.stripPrefix=false
zuul.routes.RiskQuery.serviceId=risk-computing-engin

zuul.routes.DataUpdate.path=/RiskControl/DataUpdate/0.0.1/Accounts/**
zuul.routes.DataUpdate.stripPrefix=false
zuul.routes.DataUpdate.serviceId=risk-computing-engin

zuul.max.host.connections=10000
zuul.host.socket-timeout-millis=60000
zuul.host.connect-timeout-millis=30000
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000
server.session-timeout=180

# Connect timeout used by Apache HttpClient
ribbon.ConnectTimeout=30000
# Read timeout used by Apache HttpClient
ribbon.ReadTimeout=60000

#日志
logging.file=@logging.file@
#logging.level.root=DEBUG
logging.level.root=@logging.level.root@
logging.level.com.cjhx.risk.control=debug

  1. config-beta.properties
eureka.client.serviceUrl.defaultZone=http\://xx.xx.xx.xx\:8762/eureka/
logging.level.root=info
logging.file=/app/applogs/gateway/gateway.log
  1. App 启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@EnableZuulProxy // 激活zuul 集合了@EnableCircuitBreaker @EnableDiscoveryClient
public class App extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    	return application.sources(App.class);
    }

	// 端口:8080,以配置文件为准
	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

五. service

  1. pom.xml
<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.xxxx.xxxx</groupId>
		<artifactId>cloud-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>computing-engin</artifactId>
	<name>computing-engin</name>
	<packaging>war</packaging>
	<url>http://maven.apache.org</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<!-- spring-boot的web启动的jar包 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<!-- 注册服务 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>

		<!-- oracle驱动包 -->
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc6</artifactId>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.27</version>
		</dependency>

		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.3.1</version>
		</dependency>

		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-autoconfigure</artifactId>
			<version>1.2.0</version>
		</dependency>

		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.4.2</version>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>

		<dependency>
			<groupId>org.quartz-scheduler</groupId>
			<artifactId>quartz</artifactId>
			<version>2.3.0</version>
		</dependency>

		<dependency>
			<groupId>org.quartz-scheduler</groupId>
			<artifactId>quartz-jobs</artifactId>
			<version>2.3.0</version>
		</dependency>
		<!-- sping对schedule的支持 -->  
		<dependency>
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context-support</artifactId>  
        </dependency>

		<!-- swagger-ui -->
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.2.2</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.2.2</version>
		</dependency>

		<!-- for quickfix/j -->
		<dependency>
			<groupId>org.apache.mina</groupId>
			<artifactId>mina-core</artifactId>
			<version>2.0.16</version>
		</dependency>

		<dependency>
			<groupId>org.quickfixj</groupId>
			<artifactId>quickfixj-core</artifactId>
			<version>1.6.3</version>
		</dependency>

		<dependency>
			<groupId>org.quickfixj</groupId>
			<artifactId>quickfixj-all</artifactId>
			<version>1.6.3</version>
		</dependency>

		<!-- json包 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.1.25</version>
		</dependency>

		<!-- jasypt加密框架 <dependency> <groupId>org.jasypt</groupId> <artifactId>jasypt</artifactId> 
			<version>1.9.3.redhat_3</version> </dependency> -->

		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zuul</artifactId>
		</dependency>

		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
		</dependency>

		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpcore</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-cache</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-redis</artifactId>
		</dependency>

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-feign</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
		</dependency>

		<dependency>
			<groupId>com.github.ulisesbocchio</groupId>
			<artifactId>jasypt-spring-boot-starter</artifactId>
			<version>1.9</version>
		</dependency>

	</dependencies>

	<profiles>
		<profile>
			<!-- 测试环境 -->
			<id>beta</id>
			<properties>
				<profiles.active>beta</profiles.active>
			</properties>
			
			<activation>
				<!-- 设置默认激活这个配置 -->
				<activeByDefault>true</activeByDefault>
			</activation>
			
		</profile>
		<profile>
			<!-- 发布环境 -->
			<id>release</id>
			<properties>
				<profiles.active>release</profiles.active>
			</properties>
		</profile>
	</profiles>

	<build>
		<!-- 打包的包名 -->
		<finalName>engin</finalName>
		<!-- 定义了变量配置文件的地址 -->
		<filters>
			<filter>src/main/resources/config/config-${profiles.active}.properties</filter>
		</filters>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<excludes>
					<exclude>config/*</exclude>
				</excludes>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
			</plugin>
			<!--<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> 
				<version>1.3.5</version> <dependencies> <dependency> <groupId>com.oracle</groupId> 
				<artifactId>ojdbc6</artifactId> <version>11.2.0.1.0</version> </dependency> 
				<dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> 
				<version>1.3.5</version> </dependency> </dependencies> <executions> <execution> 
				<id>Generate MyBatis Artifacts</id> <phase>package</phase> <goals> <goal>generate</goal> 
				</goals> </execution> </executions> <configuration> <verbose>true</verbose> 
				<overwrite>false</overwrite> <configurationFile>src/main/resources/mybatis-generator.xml</configurationFile> 
				</configuration> </plugin> -->
		</plugins>
	</build>

</project>


  1. application.properties
server.port=8087
spring.application.name=xx-service

#spring.redis.host=xx.xx.xx.xx
#spring.redis.port=6379
#spring.redis.pool.max-idle=8
#spring.redis.pool.min-idle=1
#spring.redis.pool.max-active=8
#spring.redis.pool.max-wait=-1

#不写http://前缀可能会报错
#spring.cloud.config.uri=http://localhost:8888
#spring.cloud.config.name=cloud-config
#spring.cloud.config.profile=dev

#spring.mvc.throw-exception-if-no-handler-found=true
#spring.resources.add-mappings=false

#加密因子
#jasypt.encryptor.password=123456
jasypt.encryptor.password=@jasypt.encryptor.password@

#eureka服务注册地址
#eureka.client.serviceUrl.defaultZone=http\://xx.xx.xx.xx\:8761/eureka/
#eureka.client.serviceUrl.defaultZone=http\://localhost\:8761/eureka/
eureka.client.serviceUrl.defaultZone=@eureka.client.serviceUrl.defaultZone@

#等待fix返回结果休眠时间(毫秒)
fix.waitsleeptime=500

#fix返回结果轮询次数
fix.waitcount=20

#请求和响应GZIP压缩支持
feign.compression.request.enabled=true
feign.compression.response.enabled=true
#支持压缩的mime types
feign.compression.request.enabled=true
feign.compression.request.mime-types=text/xml,application/xml,application/json
feign.compression.request.min-request-size=2048

#设置http参数限制
server.tomcat.max-http-header-size=3145728

#mybatis mapper配置文件地址
mybatis.mapper-locations:classpath*:mappers/*.xml

mybatis.type-aliases-package=com.cjhx.risk.*.domain
mybatis.type-handlers-package=
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=30

#zuul重定向
zuul.routes.riskcheck.path=/RiskControl/CheckRisk/0.0.1/Accounts/**
zuul.routes.riskcheck.url=forward:/riskCheck

zuul.routes.tryrisk.path=/RiskControl/TryRisk/0.0.1/Accounts/**
zuul.routes.tryrisk.url=forward:/riskCheck

zuul.routes.riskquery.path=/RiskControl/RiskQuery/0.0.1/Accounts/**
zuul.routes.riskquery.url=forward:/getRcResult

zuul.routes.dataupdate.path=/RiskControl/DataUpdate/0.0.1/Accounts/**
zuul.routes.dataupdate.url=forward:/dataUpdate

zuul.max.host.connections=5000
zull.host.socket-timeout-millis=150000
zull.host.connect-timeout-millis=150000
server.session-timeout=180

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000

#日志级别配置
logging.file=@logging.file@
#logging.level.root=DEBUG
logging.level.root=@logging.level.root@
logging.level.com.cjhx.risk=debug
logging.level.sample.mybatis.mapper=TRACE
logging.config=classpath:logback-spring.xml

  1. App 启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RestController;


@RestController
@SpringBootApplication
@EnableDiscoveryClient
@EnableTransactionManagement
@EnableAsync //支持异步调用
@EnableZuulProxy
@EnableFeignClients(basePackages = {"com.cjhx.risk.computing.adapter.feign"})
@ServletComponentScan
public class App extends SpringBootServletInitializer {

	 @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    	return application.sources(App.class);
    }

	public static void main(String[] args) {
		SpringApplication.run(App .class, args);
	}
}

转载于:https://my.oschina.net/u/2611678/blog/1819038

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值