Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dm_project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姚本章
dm_project
Commits
1ea71617
Commit
1ea71617
authored
Dec 02, 2020
by
machengbo
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dm_dev' of
http://gitlab.ioubuy.cn/yaobenzhang/dm_project
into dm_dev
parents
4c552a39
b56526e3
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
574 additions
and
109 deletions
+574
-109
pom.xml
jz-dm-apigateway/pom.xml
+71
-38
ApiGatewayApplication.java
...rc/main/java/com/jz/dm/gateway/ApiGatewayApplication.java
+4
-2
DatabaseConfig.java
...rc/main/java/com/jz/dm/gateway/config/DatabaseConfig.java
+254
-0
MybatisPlusConfig.java
...main/java/com/jz/dm/gateway/config/MybatisPlusConfig.java
+34
-0
DataGoodsApiDao.java
...c/main/java/com/jz/dm/gateway/mapper/DataGoodsApiDao.java
+3
-1
application-dev.yml
jz-dm-apigateway/src/main/resources/application-dev.yml
+24
-52
application.yml
jz-dm-apigateway/src/main/resources/application.yml
+46
-15
DataGoodsApiDao.xml
...-apigateway/src/main/resources/mapper/DataGoodsApiDao.xml
+3
-1
Property.java
jz-dm-apigateway/src/test/java/domian/Property.java
+34
-0
SpringTestCase.java
jz-dm-apigateway/src/test/java/domian/SpringTestCase.java
+15
-0
GatewayTest.java
...-apigateway/src/test/java/domian/TestApi/GatewayTest.java
+36
-0
TestApplicationContextInitializer.java
...c/test/java/domian/TestApplicationContextInitializer.java
+50
-0
No files found.
jz-dm-apigateway/pom.xml
View file @
1ea71617
...
...
@@ -9,77 +9,110 @@
<artifactId>
jz-dm-apigateway
</artifactId>
<name>
jz-dm-apigateway
</name>
<description>
jz-dm-apigateway
</description>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-autoconfigure
</artifactId>
<version>
1.5.2.RELEASE
</version>
<scope>
compile
</scope>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.6
</version>
</dependency>
<
!--<
dependency>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session
</artifactId>
<version>
1.3.0.RELEASE
</version>
<scope>
compile
</scope>
</dependency>-->
<dependency>
<groupId>
org.mybatis
</groupId>
<artifactId>
mybatis-spring
</artifactId>
<version>
1.2.2
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
</dependency>
<!-- spring-boot 相关依赖 -->
<dependency>
<groupId>
org.mybatis
</groupId>
<artifactId>
mybatis
</artifactId>
<version>
3.2.7
</version>
<scope>
compile
</scope>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-jdbc
</artifactId>
<version>
4.3.2.RELEASE
</version>
<scope>
compile
</scope>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<version>
1.5.2.RELEASE
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-
jdbc
</artifactId>
<artifactId>
spring-boot-starter-
freemarker
</artifactId>
</dependency>
<!--Redis集中存储Session-->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpcore
</artifactId>
<version>
4.4.10
</version>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-data-redis
</artifactId>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</dependency>
<!-- spring boot 和mybatis -->
<!--<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>-->
<!-- mybatis plus -->
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
</dependency>
<!--mybatis分页插件 -->
<dependency>
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper
</artifactId>
</dependency>
<!-- druid数据库连接池 -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
</dependency>
<!-- mysql连接 -->
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
6.0.6
</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>
com.zaxxer
</groupId>
<artifactId>
HikariCP
</artifactId>
<version>
3.1.0
</version>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.6
</version>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<!-- swagger2接口文档 -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
</dependency>
<dependency>
<groupId>
com.github.xiaoymin
</groupId>
<artifactId>
swagger-bootstrap-ui
</artifactId>
</dependency>
<!--工具类-->
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
<dependency>
<groupId>
com.jz.common
</groupId>
<artifactId>
jz-dm-common
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
jz-dm-apigateway/src/main/java/com/jz/dm/gateway/ApiGatewayApplication.java
View file @
1ea71617
...
...
@@ -2,14 +2,16 @@ package com.jz.dm.gateway;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.context.annotation.ComponentScan
;
/**
* @author key
*/
@SpringBootApplication
//
@ComponentScan(basePackages = {"com.jz.dm"})
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
@ComponentScan
(
basePackages
=
{
"com.jz.dm"
})
@MapperScan
(
"com.jz.dm.gateway.mapper"
)
public
class
ApiGatewayApplication
{
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/gateway/config/DatabaseConfig.java
0 → 100644
View file @
1ea71617
package
com
.
jz
.
dm
.
gateway
.
config
;
import
com.alibaba.druid.pool.DruidDataSource
;
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.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
javax.sql.DataSource
;
import
java.sql.SQLException
;
/**
* @ProjectName zhaxinle
* @Author: zeroJun
* @Date: 2018/8/16 16:49
* @Description: 主数据源配置类
*/
@Configuration
// 前缀为primary.datasource.druid的配置信息
@ConfigurationProperties
(
prefix
=
"spring.datasource"
)
@MapperScan
(
basePackages
=
DatabaseConfig
.
PACKAGE
,
sqlSessionFactoryRef
=
"sqlSessionFactory"
)
public
class
DatabaseConfig
{
/**
* dao层的包路径
*/
static
final
String
PACKAGE
=
"com.jz.dm.gateway.mapper"
;
/**
* mapper文件的相对路径
*/
private
static
final
String
MAPPER_LOCATION
=
"classpath:/mapper/*.xml"
;
private
String
filters
;
private
String
url
;
private
String
username
;
private
String
password
;
private
String
driverClassName
;
private
int
initialSize
;
private
int
minIdle
;
private
int
maxActive
;
private
long
maxWait
;
private
long
timeBetweenEvictionRunsMillis
;
private
long
minEvictableIdleTimeMillis
;
private
String
validationQuery
;
private
boolean
testWhileIdle
;
private
boolean
testOnBorrow
;
private
boolean
testOnReturn
;
private
boolean
poolPreparedStatements
;
private
int
maxPoolPreparedStatementPerConnectionSize
;
// 主数据源使用@Primary注解进行标识
//@Primary
@Bean
(
name
=
"dataSource"
)
public
DataSource
dataSource
()
throws
SQLException
{
DruidDataSource
druid
=
new
DruidDataSource
();
// 监控统计拦截的filters
druid
.
setFilters
(
filters
);
// 配置基本属性
druid
.
setDriverClassName
(
driverClassName
);
druid
.
setUsername
(
username
);
druid
.
setPassword
(
password
);
druid
.
setUrl
(
url
);
//初始化时建立物理连接的个数
druid
.
setInitialSize
(
initialSize
);
//最大连接池数量
druid
.
setMaxActive
(
maxActive
);
//最小连接池数量
druid
.
setMinIdle
(
minIdle
);
//获取连接时最大等待时间,单位毫秒。
druid
.
setMaxWait
(
maxWait
);
//间隔多久进行一次检测,检测需要关闭的空闲连接
druid
.
setTimeBetweenEvictionRunsMillis
(
timeBetweenEvictionRunsMillis
);
//一个连接在池中最小生存的时间
druid
.
setMinEvictableIdleTimeMillis
(
minEvictableIdleTimeMillis
);
//用来检测连接是否有效的sql
druid
.
setValidationQuery
(
validationQuery
);
//建议配置为true,不影响性能,并且保证安全性。
druid
.
setTestWhileIdle
(
testWhileIdle
);
//申请连接时执行validationQuery检测连接是否有效
druid
.
setTestOnBorrow
(
testOnBorrow
);
druid
.
setTestOnReturn
(
testOnReturn
);
//是否缓存preparedStatement,也就是PSCache,oracle设为true,mysql设为false。分库分表较多推荐设置为false
druid
.
setPoolPreparedStatements
(
poolPreparedStatements
);
// 打开PSCache时,指定每个连接上PSCache的大小
druid
.
setMaxPoolPreparedStatementPerConnectionSize
(
maxPoolPreparedStatementPerConnectionSize
);
return
druid
;
}
// 创建该数据源的事务管理
@Primary
@Bean
(
name
=
"transactionManager"
)
public
DataSourceTransactionManager
transactionManager
()
throws
SQLException
{
return
new
DataSourceTransactionManager
(
dataSource
());
}
// 创建Mybatis的连接会话工厂实例
@Primary
@Bean
(
name
=
"sqlSessionFactory"
)
public
SqlSessionFactory
sqlSessionFactory
(
@Qualifier
(
"dataSource"
)
DataSource
dataSource
)
throws
Exception
{
final
SqlSessionFactoryBean
sessionFactory
=
new
SqlSessionFactoryBean
();
sessionFactory
.
setDataSource
(
dataSource
);
// 设置数据源bean
sessionFactory
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
()
.
getResources
(
DatabaseConfig
.
MAPPER_LOCATION
));
// 设置mapper文件路径
return
sessionFactory
.
getObject
();
}
public
String
getFilters
()
{
return
filters
;
}
public
void
setFilters
(
String
filters
)
{
this
.
filters
=
filters
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getDriverClassName
()
{
return
driverClassName
;
}
public
void
setDriverClassName
(
String
driverClassName
)
{
this
.
driverClassName
=
driverClassName
;
}
public
int
getInitialSize
()
{
return
initialSize
;
}
public
void
setInitialSize
(
int
initialSize
)
{
this
.
initialSize
=
initialSize
;
}
public
int
getMinIdle
()
{
return
minIdle
;
}
public
void
setMinIdle
(
int
minIdle
)
{
this
.
minIdle
=
minIdle
;
}
public
int
getMaxActive
()
{
return
maxActive
;
}
public
void
setMaxActive
(
int
maxActive
)
{
this
.
maxActive
=
maxActive
;
}
public
long
getMaxWait
()
{
return
maxWait
;
}
public
void
setMaxWait
(
long
maxWait
)
{
this
.
maxWait
=
maxWait
;
}
public
long
getTimeBetweenEvictionRunsMillis
()
{
return
timeBetweenEvictionRunsMillis
;
}
public
void
setTimeBetweenEvictionRunsMillis
(
long
timeBetweenEvictionRunsMillis
)
{
this
.
timeBetweenEvictionRunsMillis
=
timeBetweenEvictionRunsMillis
;
}
public
long
getMinEvictableIdleTimeMillis
()
{
return
minEvictableIdleTimeMillis
;
}
public
void
setMinEvictableIdleTimeMillis
(
long
minEvictableIdleTimeMillis
)
{
this
.
minEvictableIdleTimeMillis
=
minEvictableIdleTimeMillis
;
}
public
String
getValidationQuery
()
{
return
validationQuery
;
}
public
void
setValidationQuery
(
String
validationQuery
)
{
this
.
validationQuery
=
validationQuery
;
}
public
boolean
isTestWhileIdle
()
{
return
testWhileIdle
;
}
public
void
setTestWhileIdle
(
boolean
testWhileIdle
)
{
this
.
testWhileIdle
=
testWhileIdle
;
}
public
boolean
isTestOnBorrow
()
{
return
testOnBorrow
;
}
public
void
setTestOnBorrow
(
boolean
testOnBorrow
)
{
this
.
testOnBorrow
=
testOnBorrow
;
}
public
boolean
isTestOnReturn
()
{
return
testOnReturn
;
}
public
void
setTestOnReturn
(
boolean
testOnReturn
)
{
this
.
testOnReturn
=
testOnReturn
;
}
public
boolean
isPoolPreparedStatements
()
{
return
poolPreparedStatements
;
}
public
void
setPoolPreparedStatements
(
boolean
poolPreparedStatements
)
{
this
.
poolPreparedStatements
=
poolPreparedStatements
;
}
public
int
getMaxPoolPreparedStatementPerConnectionSize
()
{
return
maxPoolPreparedStatementPerConnectionSize
;
}
public
void
setMaxPoolPreparedStatementPerConnectionSize
(
int
maxPoolPreparedStatementPerConnectionSize
)
{
this
.
maxPoolPreparedStatementPerConnectionSize
=
maxPoolPreparedStatementPerConnectionSize
;
}
}
\ No newline at end of file
jz-dm-apigateway/src/main/java/com/jz/dm/gateway/config/MybatisPlusConfig.java
0 → 100644
View file @
1ea71617
package
com
.
jz
.
dm
.
gateway
.
config
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
/**
* @ClassName: MybatisPlusConfig
* @Author Bellamy
* @Date 2020/11/27
* @Version 1.0
*/
@EnableTransactionManagement
@Configuration
@MapperScan
(
"com.jz.dm.gateway.mapper"
)
public
class
MybatisPlusConfig
{
@Bean
public
PaginationInterceptor
paginationInterceptor
()
{
PaginationInterceptor
paginationInterceptor
=
new
PaginationInterceptor
();
// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
// paginationInterceptor.setOverflow(false);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
paginationInterceptor
.
setLimit
(
500
);
// 开启 count 的 join 优化,只针对部分 left join
paginationInterceptor
.
setCountSqlParser
(
new
JsqlParserCountOptimize
(
true
));
return
paginationInterceptor
;
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/gateway/mapper/DataGoodsApiDao.java
View file @
1ea71617
...
...
@@ -3,6 +3,8 @@ package com.jz.dm.gateway.mapper;
import
com.jz.common.base.BaseMapper
;
import
com.jz.common.entity.DataGoodsApi
;
import
java.util.List
;
/**
* api商品(TDataGoodsApi)表数据库访问层
*
...
...
@@ -11,6 +13,6 @@ import com.jz.common.entity.DataGoodsApi;
*/
public
interface
DataGoodsApiDao
extends
BaseMapper
<
DataGoodsApi
>
{
List
<
DataGoodsApi
>
findAll
();
}
\ No newline at end of file
jz-dm-apigateway/src/main/resources/application-dev.yml
View file @
1ea71617
# 测试环境配置
server
:
port
:
8088
#contextPath: /resource
management
:
port
:
54001
health
:
mail
:
enabled
:
false
#开发环境配置
spring
:
profiles
:
test
#缓存会话
redis
:
#database: 0
#host: 119.23.13.83
#port: 8007
#timeout: 5000
cluster
:
nodes
:
-
192.168.31.167:6379
-
192.168.31.167:6380
-
192.168.31.167:6381
-
192.168.31.167:6382
-
192.168.31.167:6383
-
192.168.31.167:6384
session
:
store-type
:
none
#数据库
datasource
:
url
:
jdbc:mysql://rm-wz9n399q2avsy3k6m4o.mysql.rds.aliyuncs.com:3306/wj-mkt-project?characterEncoding=utf8&useSSL=false
driverClassName
:
com.mysql.jdbc.Driver
...
...
@@ -38,48 +44,14 @@ spring:
poolPreparedStatements
:
false
maxPoolPreparedStatementPerConnectionSize
:
20
cache
:
type
:
CAFFEINE
caffeine
:
spec
:
maximumSize=1000,expireAfterWrite=30s
public-key
:
rajZdV0xpCox+2vEHFLsKq2o2XVdMaQq
redis
:
#database: 0
#host: 119.23.13.83
#port: 8007
#timeout: 5000
cluster
:
nodes
:
-
192.168.31.167:6379
-
192.168.31.167:6380
-
192.168.31.167:6381
-
192.168.31.167:6382
-
192.168.31.167:6383
-
192.168.31.167:6384
#使用redis管理session设置为redis,否则none
session
:
store-type
:
none
#mybatis的配置
mybatis
:
#配置mapper.xml文件所在路径
mapper-locations
:
classpath:mapper.*/*.xml
#配置映射类所在的包名
type-aliases-package
:
com.jz.manage.moduls.entity
logging
:
level
:
com.jz.manage
:
debug
# 跳过签名
api
:
skipFilter
:
false
#是否跳过拦截器
skipIpLimit
:
true
#是否为ip列表
maxPostSize
:
1048576
#最大支持上传文件数
supplierId
:
200314008093
#供应商ID
# 代发三要素校验定时任务
validCron
:
0/1 * * * * *
skipFilter
:
false
skipIpLimit
:
true
maxPostSize
:
1048576
supplierId
:
200314008093
# 代发三要素校验定时任务
validCron
:
0/1 * * * * *
...
...
jz-dm-apigateway/src/main/resources/application.yml
View file @
1ea71617
# 系统信息
info
:
app
:
name
:
"
@project.name@"
description
:
"
@project.description@"
version
:
"
@project.version@"
spring-boot-version
:
"
@project.parent.version@"
#服务端口和项目名称
server
:
port
:
8088
servlet
:
context-path
:
/
#Djasypt.encryptor.password
jasypt
:
encryptor
:
password
:
btcpay.com
#日志打印
logging
:
level
:
com.netflix.discovery
:
'
OFF'
org.springframework.cloud
:
'
DEBUG'
#SPRING配置文件
spring
:
application
:
name
:
九章数据平台
aop
:
proxy-target-class
:
true
profiles
:
active
:
test
sysProperties
:
session-timeout
:
3600
developerList
:
-
name
:
九章
value
:
active
:
dev
#默认使用的配置文件
http
:
encoding
:
charset
:
UTF-8
jackson
:
time-zone
:
GMT+8
date-format
:
yyyy-MM-dd HH:mm:ss
default-property-inclusion
:
NON_NULL
#MyBatis
mybatis-plus
:
mapper-locations
:
classpath:/mapper/**/*.xml
typeAliasesPackage
:
com.jz.common.entity
#type-handlers-package: com.btcpay.commons.typehandler
global-config
:
id-type
:
1
field-strategy
:
2
db-column-underline
:
true
refresh-mapper
:
true
configuration
:
map-underscore-to-camel-case
:
true
cache-enabled
:
false
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
jz-dm-apigateway/src/main/resources/mapper/DataGoodsApiDao.xml
View file @
1ea71617
...
...
@@ -20,7 +20,9 @@
<result
property=
"uptTime"
column=
"upt_time"
jdbcType=
"TIMESTAMP"
/>
<result
property=
"delFlag"
column=
"del_flag"
jdbcType=
"VARCHAR"
/>
</resultMap>
<select
id=
"findAll"
resultType=
"com.jz.common.entity.DataGoodsApi"
>
select * from t_data_goods_api
</select>
</mapper>
\ No newline at end of file
jz-dm-apigateway/src/test/java/domian/Property.java
0 → 100644
View file @
1ea71617
/**
* Copyright (c) 2011-2014 All Rights Reserved.
*/
package
domian
;
/**
*
* @author Admin
* @version $Id: Property.java 2014年8月27日 下午6:28:46 $
*/
public
class
Property
{
private
static
java
.
util
.
Properties
property
=
null
;
private
Property
()
{
}
public
static
void
init
(
java
.
util
.
Properties
props
)
{
property
=
props
;
}
public
static
void
setProperty
(
String
key
,
Object
value
)
{
property
.
put
(
key
,
value
);
}
public
static
String
getProperty
(
String
key
)
{
return
property
.
getProperty
(
key
);
}
public
static
String
getProperty
(
String
key
,
String
defaultValue
)
{
return
property
.
getProperty
(
key
,
defaultValue
);
}
}
jz-dm-apigateway/src/test/java/domian/SpringTestCase.java
0 → 100644
View file @
1ea71617
package
domian
;
import
com.jz.dm.gateway.ApiGatewayApplication
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
ApiGatewayApplication
.
class
)
// 指定spring-boot的启动类
@ContextConfiguration
(
initializers
=
{
TestApplicationContextInitializer
.
class
})
public
abstract
class
SpringTestCase
{
}
jz-dm-apigateway/src/test/java/domian/TestApi/GatewayTest.java
0 → 100644
View file @
1ea71617
package
domian
.
TestApi
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.jz.common.entity.DataGoodsApi
;
import
com.jz.dm.gateway.mapper.DataGoodsApiDao
;
import
domian.SpringTestCase
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.Collections
;
import
java.util.List
;
/**
* @author ZC
* @PACKAGE_NAME: domian.TestApi
* @PROJECT_NAME: jz-dm-parent
* @NAME: GatewayTest
* @USER: key
* @DATE: 2020-12-2/11:53
* @DAY_NAME_SHORT: 周三
* @Description:
**/
public
class
GatewayTest
extends
SpringTestCase
{
@Autowired
private
DataGoodsApiDao
dataGoodsApiDao
;
@Test
public
void
Test
(){
//List<DataGoodsApi> list= dataGoodsApiDao.findAll();
// System.out.println(list);
QueryWrapper
<
DataGoodsApi
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"goods_api"
,
1
);
DataGoodsApi
dataGoodsApi
=
dataGoodsApiDao
.
selectOne
(
wrapper
);
}
}
jz-dm-apigateway/src/test/java/domian/TestApplicationContextInitializer.java
0 → 100644
View file @
1ea71617
package
domian
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.support.GenericApplicationContext
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.core.io.support.PropertiesLoaderUtils
;
import
org.springframework.core.io.support.ResourcePatternResolver
;
import
org.springframework.util.CollectionUtils
;
import
java.io.IOException
;
import
java.util.Properties
;
/**
*
*
* @author zengfan
* @version $Id: TestApplicationContextInitializer.java 2017年6月12日 下午9:30:46 $
*/
public
class
TestApplicationContextInitializer
implements
ApplicationContextInitializer
<
GenericApplicationContext
>
{
private
Properties
props
=
null
;
/**
* @see org.springframework.context.ApplicationContextInitializer#initialize(org.springframework.context.ConfigurableApplicationContext)
*/
@Override
public
void
initialize
(
GenericApplicationContext
context
)
{
if
(
null
!=
props
)
{
return
;
}
props
=
new
Properties
();
ResourcePatternResolver
resolver
=
new
PathMatchingResourcePatternResolver
();
Resource
[]
resources
=
null
;
try
{
resources
=
resolver
.
getResources
(
"classpath:properties/*.properties"
);
for
(
Resource
res
:
resources
)
{
Properties
properties
=
PropertiesLoaderUtils
.
loadProperties
(
res
);
CollectionUtils
.
mergePropertiesIntoMap
(
properties
,
props
);
}
Property
.
init
(
props
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment