Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
d6406697
Commit
d6406697
authored
May 29, 2018
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix : 增加动态数据源配置
parent
7b3dd1c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
16 deletions
+8
-16
Bootstrap.java
src/main/java/cn/quantgroup/xyqb/Bootstrap.java
+2
-0
JpaConfig.java
src/main/java/cn/quantgroup/xyqb/config/data/JpaConfig.java
+2
-16
ImageCaptchaController.java
...b/controller/external/captcha/ImageCaptchaController.java
+4
-0
No files found.
src/main/java/cn/quantgroup/xyqb/Bootstrap.java
View file @
d6406697
package
cn
.
quantgroup
.
xyqb
;
package
cn
.
quantgroup
.
xyqb
;
import
cn.quantgroup.tech.db.EnableDynamicDataSource
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
@@ -20,6 +21,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
...
@@ -20,6 +21,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
@EnableAsync
@EnableAsync
@EnableAspectJAutoProxy
@EnableAspectJAutoProxy
@SpringBootApplication
@SpringBootApplication
@EnableDynamicDataSource
public
class
Bootstrap
{
public
class
Bootstrap
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/cn/quantgroup/xyqb/config/data/JpaConfig.java
View file @
d6406697
...
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Value;
...
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.DependsOn
;
import
org.springframework.context.annotation.DependsOn
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.orm.jpa.JpaTransactionManager
;
import
org.springframework.orm.jpa.JpaTransactionManager
;
import
org.springframework.orm.jpa.JpaVendorAdapter
;
import
org.springframework.orm.jpa.JpaVendorAdapter
;
...
@@ -54,28 +55,13 @@ public class JpaConfig {
...
@@ -54,28 +55,13 @@ public class JpaConfig {
properties
.
put
(
"hibernate.jdbc.batch_size"
,
30
);
properties
.
put
(
"hibernate.jdbc.batch_size"
,
30
);
properties
.
put
(
"hibernate.order_inserts"
,
true
);
properties
.
put
(
"hibernate.order_inserts"
,
true
);
properties
.
put
(
"hibernate.order_updates"
,
true
);
properties
.
put
(
"hibernate.order_updates"
,
true
);
entityManager
.
setJpaProperties
(
properties
);
entityManager
.
setJpaProperties
(
properties
);
entityManager
.
setJpaVendorAdapter
(
jpaVendorAdapter
());
entityManager
.
setJpaVendorAdapter
(
jpaVendorAdapter
());
entityManager
.
afterPropertiesSet
();
entityManager
.
afterPropertiesSet
();
return
entityManager
.
getObject
();
return
entityManager
.
getObject
();
}
}
@Bean
(
name
=
"dataSource"
)
public
DataSource
dataSource
()
{
HikariConfig
config
=
new
HikariConfig
();
config
.
setJdbcUrl
(
xyqbJdbcUrl
);
config
.
setPassword
(
password
);
config
.
setUsername
(
user
);
config
.
setMaximumPoolSize
(
maxPoolSize
);
config
.
setMinimumIdle
(
20
);
config
.
addDataSourceProperty
(
"cachePrepStmts"
,
"true"
);
config
.
addDataSourceProperty
(
"prepStmtCacheSize"
,
"250"
);
config
.
addDataSourceProperty
(
"prepStmtCacheSqlLimit"
,
"2048"
);
return
new
HikariDataSource
(
config
);
}
private
JpaVendorAdapter
jpaVendorAdapter
()
{
private
JpaVendorAdapter
jpaVendorAdapter
()
{
HibernateJpaVendorAdapter
hibernateJpaVendorAdapter
=
new
HibernateJpaVendorAdapter
();
HibernateJpaVendorAdapter
hibernateJpaVendorAdapter
=
new
HibernateJpaVendorAdapter
();
hibernateJpaVendorAdapter
.
setShowSql
(
false
);
hibernateJpaVendorAdapter
.
setShowSql
(
false
);
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/captcha/ImageCaptchaController.java
View file @
d6406697
...
@@ -4,6 +4,8 @@ import cn.quantgroup.xyqb.Constants;
...
@@ -4,6 +4,8 @@ import cn.quantgroup.xyqb.Constants;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
@@ -28,6 +30,7 @@ import java.util.UUID;
...
@@ -28,6 +30,7 @@ import java.util.UUID;
*/
*/
@RestController
@RestController
@RequestMapping
(
"/api"
)
@RequestMapping
(
"/api"
)
@Api
(
value
=
"/api"
,
description
=
"叫Api, 实际上是图形验证码. 你说神奇不神奇..."
)
public
class
ImageCaptchaController
{
public
class
ImageCaptchaController
{
private
static
final
String
IMAGE_FORMAT_PNG
=
"png"
;
private
static
final
String
IMAGE_FORMAT_PNG
=
"png"
;
...
@@ -42,6 +45,7 @@ public class ImageCaptchaController {
...
@@ -42,6 +45,7 @@ public class ImageCaptchaController {
* 默认匹配 GET /captcha, 提供4位数字和字母混合图片验证码
* 默认匹配 GET /captcha, 提供4位数字和字母混合图片验证码
*/
*/
@RequestMapping
(
value
=
"/captcha"
)
@RequestMapping
(
value
=
"/captcha"
)
@ApiOperation
(
value
=
"/captcha"
,
notes
=
"获取图形验证码接口, 会返回一个base64的图形验证码"
)
public
JsonResult
fetchCaptcha
(
HttpServletRequest
request
)
{
public
JsonResult
fetchCaptcha
(
HttpServletRequest
request
)
{
String
imageId
=
UUID
.
randomUUID
().
toString
();
String
imageId
=
UUID
.
randomUUID
().
toString
();
BufferedImage
challenge
=
imageCaptchaService
.
getImageChallengeForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
imageId
,
request
.
getLocale
());
BufferedImage
challenge
=
imageCaptchaService
.
getImageChallengeForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
imageId
,
request
.
getLocale
());
...
...
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