赵文轩
2024-10-31 adcfe77861db5a8791331a7727670d812a0988a6
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("数据库连接文件找不到 系统正在创建!");
                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 @@
            // 这里是测试写法,具体的value可以通过请求参数传递过来
            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("数据库连接文件找不到!");
            }
@@ -174,7 +183,8 @@
            // 这里是测试写法,具体的value可以通过请求参数传递过来
            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:sqlserver://"+props.getProperty("lisip")+":"+props.getProperty("lisprot")+";DatabaseName="+props.getProperty("lisname")+
                    ";&characterEncoding=utf8");
            properties.setProperty("druid.username",props.getProperty("lisusername"));
            properties.setProperty("druid.password",props.getProperty("lispassword"));
            dataSource.restart(properties);
@@ -196,7 +206,7 @@
            // 从文件中读取配置信息
            FileInputStream fis = null;
            try {
                fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties");
                fis = new FileInputStream(url);
            } catch (FileNotFoundException e) {
                log.info("数据库连接文件找不到");
            }
@@ -207,7 +217,8 @@
            // 这里是测试写法,具体的value可以通过请求参数传递过来
            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);