Commit d6406697 authored by xiaoguang.xu's avatar xiaoguang.xu

fix : 增加动态数据源配置

parent 7b3dd1c0
package cn.quantgroup.xyqb;
import cn.quantgroup.tech.db.EnableDynamicDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -20,6 +21,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
@EnableAsync
@EnableAspectJAutoProxy
@SpringBootApplication
@EnableDynamicDataSource
public class Bootstrap {
public static void main(String[] args) {
......
......@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
......@@ -54,28 +55,13 @@ public class JpaConfig {
properties.put("hibernate.jdbc.batch_size", 30);
properties.put("hibernate.order_inserts", true);
properties.put("hibernate.order_updates", true);
entityManager.setJpaProperties(properties);
entityManager.setJpaVendorAdapter(jpaVendorAdapter());
entityManager.afterPropertiesSet();
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() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(false);
......
......@@ -4,6 +4,8 @@ import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator;
import cn.quantgroup.xyqb.model.JsonResult;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
......@@ -28,6 +30,7 @@ import java.util.UUID;
*/
@RestController
@RequestMapping("/api")
@Api(value = "/api", description = "叫Api, 实际上是图形验证码. 你说神奇不神奇...")
public class ImageCaptchaController {
private static final String IMAGE_FORMAT_PNG = "png";
......@@ -42,6 +45,7 @@ public class ImageCaptchaController {
* 默认匹配 GET /captcha, 提供4位数字和字母混合图片验证码
*/
@RequestMapping(value = "/captcha")
@ApiOperation(value = "/captcha", notes = "获取图形验证码接口, 会返回一个base64的图形验证码")
public JsonResult fetchCaptcha(HttpServletRequest request) {
String imageId = UUID.randomUUID().toString();
BufferedImage challenge = imageCaptchaService.getImageChallengeForID(Constants.IMAGE_CAPTCHA_KEY + imageId, request.getLocale());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment