Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';t在不使用@Transactional的情况下切换AbstractRoutingDataSource_Java_Spring_Spring Boot_Transactions_Datasource - Fatal编程技术网

Java Can';t在不使用@Transactional的情况下切换AbstractRoutingDataSource

Java Can';t在不使用@Transactional的情况下切换AbstractRoutingDataSource,java,spring,spring-boot,transactions,datasource,Java,Spring,Spring Boot,Transactions,Datasource,我有一个Spring Boot项目。如上所述,我想使用AbstractRoutingDataSource切换DataSource。我不想使用@Transactional,因为不需要任何事务。 但是当我转移我的方法时,它看起来像是使用了@Transactional,但是当我在单元测试中测试我的方法时,它运行正常,我认为这很奇怪,因为在单元测试中,@Transactional不应该工作 public class DynamicDataSource extends AbstractRoutingDat

我有一个Spring Boot项目。如上所述,我想使用
AbstractRoutingDataSource
切换DataSource。我不想使用
@Transactional
,因为不需要任何事务。
但是当我转移我的方法时,它看起来像是使用了
@Transactional
,但是当我在单元测试中测试我的方法时,它运行正常,我认为这很奇怪,因为在单元测试中,
@Transactional
不应该工作

public class DynamicDataSource extends AbstractRoutingDataSource {

@Override
protected Object determineCurrentLookupKey() {
    return DynamicContextHolder.peek();
}
}

控制器方法

@RequestMapping(value = "/pipeline/analyze/{systemId}/{dbName}/{dbSchemaName}/{dbTableName}", method = RequestMethod.GET)
public String pipelineAnalyze(@PathVariable("systemId") Long systemId, @PathVariable("dbName") String dbName, @PathVariable("dbSchemaName") String dbSchemaName, @PathVariable("dbTableName") String dbTableName) throws IOException {

    ETLServerAccessEntityInterface etlServerAccessEntity = etlServer.getETLServerAccessEntity();

   /* LOGGER.info("===etlServerAccessEntity.getAccessToken()===");
    LOGGER.info(etlServerAccessEntity.getAccessToken());
    LOGGER.info("isAlive=" + etlServer.isAlive());*/


    TableInfoMasterEntity tableInfoMaster = new TableInfoMasterEntity();
    TableInfoMasterEntityPk tableInfoMasterPk = new TableInfoMasterEntityPk();
    tableInfoMasterPk.setSystemId(systemId);
    tableInfoMasterPk.setDbName(dbName);
    tableInfoMasterPk.setDbSchemaName(dbSchemaName);
    tableInfoMasterPk.setDbTableName(dbTableName);
    tableInfoMaster.setId(tableInfoMasterPk);
    Example<TableInfoMasterEntity> exampleTableInfoMaster = Example.of(tableInfoMaster);


    List<TableInfoMasterEntity> filteredTableInfoMaster = tableInfoMasterService.findAll(exampleTableInfoMaster);
    System.out.println("filteredTableInfoMaster.size()=" + filteredTableInfoMaster.size());
    TableInfoMasterEntity tableInfoMasterEntity = filteredTableInfoMaster.get(0);
    pipelineRequirementAnalyzeService.analyze(tableInfoMasterEntity);


    return String.valueOf(pipelineRequirementAnalyzeService.toString());
}
@RequestMapping(value=“/pipeline/analyze/{systemId}/{dbName}/{dbSchemaName}/{dbTableName}”,method=RequestMethod.GET)
公共字符串pipelineAnalyze(@PathVariable(“systemId”)Long systemId、@PathVariable(“dbName”)String dbName、@PathVariable(“DbChemAname”)String DbChemAname、@PathVariable(“dbTableName”)String dbTableName)引发IOException{
etlServerAccessEntity接口etlServerAccessEntity=etlServer.getETLServerAccessEntity();
/*LOGGER.info(“==etlServerAccessEntity.getAccessToken()==”;
info(etlServerAccessEntity.getAccessToken());
LOGGER.info(“isAlive=“+etlServer.isAlive())*/
TableInfoMasterEntity tableInfoMaster=新的TableInfoMasterEntity();
TableInfoMasterEntityPk tableInfoMasterPk=新的TableInfoMasterEntityPk();
tableInfoMasterPk.setSystemId(系统ID);
tableInfoMasterPk.setDbName(dbName);
tableInfoMasterPk.setDbSchemaName(dbSchemaName);
tableInfoMasterPk.setDbTableName(dbTableName);
setId(tableInfoMasterPk);
Example Example tableInfoMaster=Example.of(tableInfoMaster);
List filteredTableInfoMaster=tableInfoMasterService.findAll(例如TableInfoMaster);
System.out.println(“filteredTableInfoMaster.size()=”+filteredTableInfoMaster.size());
TableInfoMasterEntity TableInfoMasterEntity=filteredTableInfoMaster.get(0);
管道需求分析服务分析(tableInfoMasterEntity);
返回字符串.valueOf(pipelineRequirementAnalyzeService.toString());
}
单元测试

@Test
public void findByTemplateNameContaining() throws IOException {
    ETLServerAccessEntityInterface etlServerAccessEntity = etlServer.getETLServerAccessEntity();
    TableInfoMasterEntity tableInfoMaster = new TableInfoMasterEntity();
    TableInfoMasterEntityPk tableInfoMasterPk = new TableInfoMasterEntityPk();
    tableInfoMasterPk.setSystemId(1);
    tableInfoMasterPk.setDbName("DGRAMES");
    tableInfoMasterPk.setDbSchemaName("MESSERIES");
    tableInfoMasterPk.setDbTableName("TBLEMSACCESSORYSTATE_MAINTAIN");
    tableInfoMaster.setId(tableInfoMasterPk);
    Example<TableInfoMasterEntity> exampleTableInfoMaster = Example.of(tableInfoMaster);
    List<TableInfoMasterEntity> filteredTableInfoMaster = tableInfoMasterService.findAll(exampleTableInfoMaster);
    TableInfoMasterEntity tableInfoMasterEntity = filteredTableInfoMaster.get(0);
    pipelineRequirementAnalyzeService.analyze(tableInfoMasterEntity);
    System.out.println();
}
@测试
public void findByTemplateNameContaining()引发IOException{
etlServerAccessEntity接口etlServerAccessEntity=etlServer.getETLServerAccessEntity();
TableInfoMasterEntity tableInfoMaster=新的TableInfoMasterEntity();
TableInfoMasterEntityPk tableInfoMasterPk=新的TableInfoMasterEntityPk();
tableInfoMasterPk.setSystemId(1);
tableInfoMasterPk.setDbName(“DGRAMES”);
tableInfoMasterPk.setDbSchemaName(“MESSERIES”);
tableInfoMasterPk.setDbTableName(“TBLEMSACCESSORYSTATE_维护”);
setId(tableInfoMasterPk);
Example Example tableInfoMaster=Example.of(tableInfoMaster);
List filteredTableInfoMaster=tableInfoMasterService.findAll(例如TableInfoMaster);
TableInfoMasterEntity TableInfoMasterEntity=filteredTableInfoMaster.get(0);
管道需求分析服务分析(tableInfoMasterEntity);
System.out.println();
}
这两种方法类似,它们都传输
pipelineRequirementAnalyzeService.analyze(tableInfoMasterEntity)
但结果是不同的。这是和