From b98bda282397df60077efbe4c1ad35a44bdfffb9 Mon Sep 17 00:00:00 2001 From: zhaowenxuan <chacca165@163.com> Date: 星期一, 02 十二月 2024 17:57:17 +0800 Subject: [PATCH] 2024-12-02 --- ltkj-framework/src/main/java/com/ltkj/framework/config/DruidConfig.java | 32 +++++++++++++++++++++----------- 1 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ltkj-framework/src/main/java/com/ltkj/framework/config/DruidConfig.java b/ltkj-framework/src/main/java/com/ltkj/framework/config/DruidConfig.java index 21a21ab..9282963 100644 --- a/ltkj-framework/src/main/java/com/ltkj/framework/config/DruidConfig.java +++ b/ltkj-framework/src/main/java/com/ltkj/framework/config/DruidConfig.java @@ -17,6 +17,7 @@ import com.ltkj.system.service.ISysConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; @@ -39,6 +40,13 @@ @Slf4j public class DruidConfig { + @Value ("${config.properties}") + private String url; + + @Value ("${config.path}") + private String path; + + @Bean // @ConfigurationProperties("spring.datasource.druid.master") public DataSource masterDataSource(DruidProperties druidProperties) { @@ -48,15 +56,15 @@ // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 FileInputStream fis = null; try { - fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties"); + fis = new FileInputStream(url); } catch (FileNotFoundException e) { log.info("鏁版嵁搴撹繛鎺ユ枃浠舵壘涓嶅埌 绯荤粺姝e湪鍒涘缓锛�"); - File f = new File("D:\\ltkjprojectconf"); + File f = new File(path); if(!f.exists()){ f.mkdirs(); } - File file = new File("D:\\ltkjprojectconf\\config.properties"); + File file = new File(url); try { FileWriter fileWriter = new FileWriter(file); fileWriter.write("ip = 浣犵殑涓绘暟鎹簱杩炴帴ip鍦板潃\n"); @@ -130,7 +138,7 @@ // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 FileInputStream fis = null; try { - fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties"); + fis = new FileInputStream(url); } catch (FileNotFoundException e) { log.info("鏁版嵁搴撹繛鎺ユ枃浠舵壘涓嶅埌锛�"); } @@ -141,11 +149,12 @@ // 杩欓噷鏄祴璇曞啓娉曪紝鍏蜂綋鐨剉alue鍙互閫氳繃璇锋眰鍙傛暟浼犻�掕繃鏉� properties.setProperty("druid.enabled",props.getProperty("hisenabled")); properties.setProperty("druid.driverClassName","com.microsoft.sqlserver.jdbc.SQLServerDriver"); - properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("hisip")+":"+props.getProperty("hisprot")+";DatabaseName="+props.getProperty("hisname")); + properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("hisip")+":"+props.getProperty("hisprot")+";DatabaseName="+props.getProperty("hisname")+ + ";&characterEncoding=utf8"); properties.setProperty("druid.username",props.getProperty("hisusername")); properties.setProperty("druid.password",props.getProperty("hispassword")); dataSource.restart(properties); - log.info("鏁版嵁搴撹繛鎺ユ垚鍔�!!!"); + log.info("his鏁版嵁搴撹繛鎺ユ垚鍔�!!!"); } catch (Exception e) { log.info("鏁版嵁搴撹繛鎺ュけ璐� 璇疯仈绯荤鐞嗗憳锛�"); e.printStackTrace(); @@ -163,7 +172,7 @@ // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 FileInputStream fis = null; try { - fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties"); + fis = new FileInputStream(url); } catch (FileNotFoundException e) { log.info("鏁版嵁搴撹繛鎺ユ枃浠舵壘涓嶅埌锛�"); } @@ -173,8 +182,8 @@ Properties properties = new Properties(); // 杩欓噷鏄祴璇曞啓娉曪紝鍏蜂綋鐨剉alue鍙互閫氳繃璇锋眰鍙傛暟浼犻�掕繃鏉� properties.setProperty("druid.enabled",props.getProperty("lisenabled")); - properties.setProperty("druid.driverClassName","com.microsoft.sqlserver.jdbc.SQLServerDriver"); - properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("lisip")+":"+props.getProperty("lisprot")+";DatabaseName="+props.getProperty("lisname")); + properties.setProperty("druid.url","jdbc:mysql://"+props.getProperty("lisip")+":"+props.getProperty("lisprot")+"/"+props.getProperty("lisname")+"" + + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"); properties.setProperty("druid.username",props.getProperty("lisusername")); properties.setProperty("druid.password",props.getProperty("lispassword")); dataSource.restart(properties); @@ -196,7 +205,7 @@ // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 FileInputStream fis = null; try { - fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties"); + fis = new FileInputStream(url); } catch (FileNotFoundException e) { log.info("鏁版嵁搴撹繛鎺ユ枃浠舵壘涓嶅埌"); } @@ -207,7 +216,8 @@ // 杩欓噷鏄祴璇曞啓娉曪紝鍏蜂綋鐨剉alue鍙互閫氳繃璇锋眰鍙傛暟浼犻�掕繃鏉� properties.setProperty("druid.enabled",props.getProperty("pacsenabled")); properties.setProperty("druid.driverClassName","com.microsoft.sqlserver.jdbc.SQLServerDriver"); - properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("pacsip")+":"+props.getProperty("pacsprot")+";DatabaseName="+props.getProperty("pacsname")); + properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("pacsip")+":"+props.getProperty("pacsprot")+";DatabaseName="+props.getProperty("pacsname")+ + ";&characterEncoding=utf8"); properties.setProperty("druid.username",props.getProperty("pacsusername")); properties.setProperty("druid.password",props.getProperty("pacspassword")); dataSource.restart(properties); -- Gitblit v1.8.0