diff --git a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/ds/MybatisDataSourceConfig.java b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/ds/MybatisDataSourceConfig.java index f8f7645bd..ef83eac72 100644 --- a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/ds/MybatisDataSourceConfig.java +++ b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/ds/MybatisDataSourceConfig.java @@ -13,12 +13,15 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import org.springframework.jdbc.datasource.SimpleDriverDataSource; +import org.springframework.jdbc.datasource.AbstractDataSource; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.unidal.dal.jdbc.datasource.DataSource; import org.unidal.dal.jdbc.datasource.DataSourceManager; import org.unidal.lookup.ContainerLoader; +import java.sql.Connection; +import java.sql.SQLException; + @Configuration @Profile(AbstractProfile.PROFILE_NAME_PRODUCTION) @MapperScan("com.ctrip.xpipe.redis.console.mapper") @@ -27,6 +30,7 @@ public class MybatisDataSourceConfig { private static final Logger logger = LoggerFactory.getLogger(MybatisDataSourceConfig.class); private XPipeDataSource dataSource; + private CommonConfigBean commonConfigBean = new CommonConfigBean(); @Bean @@ -40,8 +44,8 @@ public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() throws Except public javax.sql.DataSource dataSource() throws Exception { if(commonConfigBean.disableDb()) { - // if disableDb is true, datasource is useless, only for autowired - return new SimpleDriverDataSource(); + // if disableDb is true, set a fake datasource, only for autowired. + return makeFakeDataSource(); } // 强制查询使Xpipe DataSource初始化 ConfigTblDao configTblDao = ContainerLoader.getDefaultContainer().lookup(ConfigTblDao.class); @@ -84,4 +88,17 @@ private XPipeDataSource tryGetXpipeDataSource() { return this.dataSource; } } + + private javax.sql.DataSource makeFakeDataSource() { + return new AbstractDataSource() { + @Override + public Connection getConnection() throws SQLException { + throw new SQLException("This is a fake datasource"); + } + @Override + public Connection getConnection(String username, String password) throws SQLException { + throw new SQLException("This is a fake datasource"); + } + }; + } } diff --git a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/ds/XPipeDataSource.java b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/ds/XPipeDataSource.java index f67cac0af..9ff2179dc 100644 --- a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/ds/XPipeDataSource.java +++ b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/ds/XPipeDataSource.java @@ -1,6 +1,7 @@ package com.ctrip.xpipe.redis.console.ds; import com.ctrip.xpipe.datasource.DataSourceFactory; +import com.ctrip.xpipe.redis.checker.config.impl.CommonConfigBean; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.LogEnabled; import org.slf4j.Logger; @@ -34,6 +35,8 @@ public class XPipeDataSource extends ContainerHolder implements DataSource, LogE private static final String ctripDalDataSourceFactory = "com.ctrip.xpipe.service.datasource.CtripDalDataSourceFactory"; + private CommonConfigBean commonConfigBean = new CommonConfigBean(); + private static boolean ctripDataSourceEnabled = ClassUtils.isPresent(ctripDalDataSource, XPipeDataSource.class.getClassLoader()); @@ -52,7 +55,7 @@ public DataSourceDescriptor getDescriptor() { @Override public void initialize(DataSourceDescriptor descriptor) { - if (ctripDataSourceEnabled) { + if (ctripDataSourceEnabled && !commonConfigBean.disableDb()) { try { m_factory = (DataSourceFactory)(Class.forName(ctripDalDataSourceFactory).newInstance()); Class clazz = Class.forName(ctripDalDataSource); diff --git a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/spring/DalIgniteValidateLoadConfig.java b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/spring/DalIgniteValidateLoadConfig.java index 4ab2e0721..6f3c65981 100644 --- a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/spring/DalIgniteValidateLoadConfig.java +++ b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/spring/DalIgniteValidateLoadConfig.java @@ -1,6 +1,8 @@ package com.ctrip.xpipe.redis.console.spring; import com.ctrip.xpipe.redis.checker.spring.ConsoleDisableDbCondition; +import com.ctrip.xpipe.redis.checker.spring.ConsoleServerMode; +import com.ctrip.xpipe.redis.checker.spring.ConsoleServerModeCondition; import com.ctrip.xpipe.redis.checker.spring.DisableDbMode; import com.ctrip.xpipe.spring.AbstractProfile; import org.springframework.context.annotation.ComponentScan; @@ -13,6 +15,7 @@ @DisableDbMode(false) @ComponentScan(basePackages = {"com.ctrip.xpipe.service.ignite"}) @Profile(AbstractProfile.PROFILE_NAME_PRODUCTION) +@ConsoleServerMode(ConsoleServerModeCondition.SERVER_MODE.CONSOLE) public class DalIgniteValidateLoadConfig { // only config not set disable db, then laod com.ctrip.xpipe.service.ignite.DalIgniteValidate }