Springboot无法自动注入JdbcTemplate,非maven

WonHyo 2018-03-22 04:45:41
注意了,我没有用到maven,也没有pom.xml文件。需要的jar包我都是自己导进项目的。
在dao层配置注解

@Repository("wxDao")
public class WxDaoImpl implements WxDao {
@Autowired
private JdbcTemplate jt;

@Override
public List<Map<String, Object>> getUserList() {
// TODO Auto-generated method stub
String sql="select * from userTable";
System.out.println("success");
return null;
}
}

启动入口类,报错找不到JdbcTemplate的bean,主要报错如下

2018-03-22 16:21:25.222 WARN 10860 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'wxController': Unsatisfied dependency expressed through field 'wxService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wxService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'wxDao': Unsatisfied dependency expressed through field 'jt'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.jdbc.core.JdbcTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2018-03-22 16:21:25.226 INFO 10860 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2018-03-22 16:21:25.239 WARN 10860 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase : The web application [weappservice] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)
2018-03-22 16:21:25.254 INFO 10860 --- [ main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-03-22 16:21:25.398 ERROR 10860 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

Field jt in com.weapp.dao.impl.WxDaoImpl required a bean of type 'org.springframework.jdbc.core.JdbcTemplate' that could not be found.
- Bean method 'jdbcTemplate' not loaded because @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans


Action:

Consider revisiting the conditions above or defining a bean of type 'org.springframework.jdbc.core.JdbcTemplate' in your configuration.

配置文件数据库相关配置

###### dbsource######
spring.datasource.url=jdbc:mysql://localhost:3306/wxapp
spring.datasource.username=root
spring.datasource.password=sql12345
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

这个问题卡了很久,求解答
...全文
3146 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 3 楼 WonHyo 的回复:
[quote=引用 1 楼 ledzcl 的回复:]

添加数据源配置,导入阿里巴巴的数据源jar包druid,正常启动了[/quote]
没用
WonHyo 2018-03-22
  • 打赏
  • 举报
回复
引用 1 楼 ledzcl 的回复:
添加数据源配置,导入阿里巴巴的数据源jar包druid,正常启动了
ledzcl 2018-03-22
  • 打赏
  • 举报
回复
qq827010202 2018-03-22
  • 打赏
  • 举报
回复
这种情况一般是配置文件没有加载进来

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧