美文网首页
spring-boot项目中datasource可选

spring-boot项目中datasource可选

作者: alex102400 | 来源:发表于2020-03-03 20:30 被阅读0次

/**

* 是否启用数据库的配置控制。主要是控制是否启用druid

*/

@Configuration

@AutoConfigureBefore(DruidDataSourceAutoConfigure.class)

public class DbEnableConfiguration {

private static final Loggerlog = LogManager.getLogger();

    @Bean

    @ConditionalOnProperty(name ="app.datasource.enable", havingValue ="false")

public DataSourcedataSource() {

log.info("Init NoopDataSource");

        return new NoopDataSource();

    }

/**

* 空数据源实现

*/

    public static class NoopDataSourceimplements javax.sql.DataSource {

@Override

        public ConnectiongetConnection()throws SQLException {

return null;

        }

@Override

        public ConnectiongetConnection(String username, String password)throws SQLException {

return null;

        }

@Override

        public T unwrap(Class iface)throws SQLException {

return null;

        }

@Override

        public boolean isWrapperFor(Class iface)throws SQLException {

return false;

        }

@Override

        public PrintWritergetLogWriter()throws SQLException {

return null;

        }

@Override

        public void setLogWriter(PrintWriter out)throws SQLException {

}

@Override

        public void setLoginTimeout(int seconds)throws SQLException {

}

@Override

        public int getLoginTimeout()throws SQLException {

return 0;

        }

@Override

        public java.util.logging.LoggergetParentLogger()throws SQLFeatureNotSupportedException {

return null;

        }

}

}

相关文章

网友评论

      本文标题:spring-boot项目中datasource可选

      本文链接:https://www.haomeiwen.com/subject/qwyquctx.html