简体   繁体   English

Spring jdbctemplate,数据源,transactionManager

[英]Spring jdbctemplate, datasource, transactionManager

For a test, i have a abstract class. 为了测试,我有一个抽象类。

public abstract class BaseTestClass

  private JdbcTemplate jdbcTemplate;

  @Autowired
  public void setDataSource(DataSource dataSource)
  {
  this.setJdbcTemplate(new JdbcTemplate(dataSource));
  }
  ...
}


@Transactional
@ContextConfiguration(locations = {"/spring/test/test-dao-context.xml"})
public class TestUser extends BaseTestClass{
...
}

In test-dao-context.xml file, i have my transaction manager and datasource. 在test-dao-context.xml文件中,我有事务管理器和数据源。

SetDataSource is never called, so i get a null pointerException when i try to do a test. 永远不会调用SetDataSource,因此当我尝试进行测试时,我得到一个null pointerException。

You need to run you test with an appropriate runner which is SpringJUnit4ClassRunner for Spring driven tests. 您需要使用适当的运行程序运行测试,该运行程序是用于Spring驱动的测试的SpringJUnit4ClassRunner Otherwise nothing will get injected anywhere as there is no Spring Container managing all the instances. 否则,任何地方都不会注入任何东西,因为没有Spring Container管理所有实例。

Check Spring Unit Testing for details. 有关详细信息,请检查弹簧单元测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring启动时的TransactionManager和数据源 - 弹簧数据 - TransactionManager and datasource in spring boot - spring data 使用 Spring JdbcTemplate - 注入数据源 vs jdbcTemplate - using Spring JdbcTemplate - injecting datasource vs jdbcTemplate Spring Boot 找不到 JdbcTemplate 的数据源 - Spring Boot can't find DataSource for JdbcTemplate Spring Framework IllegalArgumentException'dataSource'或'jdbcTemplate'是必需的JAVA - Spring Framework IllegalArgumentException 'dataSource' or 'jdbcTemplate' is required JAVA Spring Boot中的多个DataSource和JdbcTemplate(> 1.1.0) - Multiple DataSource and JdbcTemplate in Spring Boot (> 1.1.0) 如何在Spring JDBCTemplate中为数据源设置区分大小写``关闭'' - How do i set case sensitivity 'off' for a Datasource in spring jdbctemplate Spring JDBCTemplate除了Apache Commons之外还有其他MySQL数据源吗? - Spring JDBCTemplate other MySQL datasource than apache commons? Spring 工厂方法“jdbcTemplate”抛出异常; 属性“数据源”是必需的 - Spring Factory method 'jdbcTemplate' threw exception; Property 'dataSource' is required Spring JDBCTemplate 与 Hikari 数据源批量更新行为异步 - Spring JDBCTemplate with Hikari datasource batch update behaving asynchronously JdbcTemplate 与 TransactionManager 究竟如何协同工作? - How exactly JdbcTemplate with TransactionManager works together?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM