JdbcTemplate空指针异常

若没有注入。则报空指针异常。

也会报:Failed to configure a DataSource: 'url' attribute is not specified and no em.....

也会报: Servlet.service() for servlet [dispatcherServlet] in context with path []

解决方法:

1、业务层实现类中:xxxServiceImpl 中的 Repository 加入: @Resource注解。

@Resource
private XxxxRepository xxxRepository;

2、在:Repository层:加入:@Resource(name="xxxxJdbcTemplate")。

@Repository
public class XxxxxRepository {

@Resource(name="xxxxJdbcTemplate")
protected JdbcTemplate xxxxJdbcTemplate;

  

相关文章:【已应用】落地项目中使用的JdbcTemplate-包含application.properties配置 【JdbcTemplateDemo】【实用】 

posted @ 2023-10-23 10:56  刘贵庆  阅读(46)  评论(0编辑  收藏  举报