Spring boot JdbcTemplate 自动注入失败
 @Repository
public class UserDataImpl implements UserData {

    @Autowired
    JdbcTemplate jdbcTemplate;
}
 2017-07-06 17:37:20.523 ERROR 2990 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

java.lang.NullPointerException: null
    at com.marnon.service.UserService.userCheck(UserService.java:30) ~[classes/:na]
    at com.marnon.controller.MyController.logIn(MyController.java:45) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
    at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426) ~[springloaded-1.2.6.RELEASE.jar:1.2.6.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]

4个回答

UserService.java:3030行的代码贴出来看看。另外要说明的是,如果JdbcTemplate注入失败的话,会在启动的时候就报出来,而不是当你调用方法的时候

qq_36263935
qq_36263935 回复Hreyar: 你好,请问这个问题是怎么解决的?
一年多之前 回复
mhw213212
Hreyar 谢谢已经解决了
大约 2 年之前 回复
Lujinlong56789
星星的愿望56789 原来如此,谢谢指点
大约 2 年之前 回复
 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

为什么啊,求大神指点一下,已经弄了一下午了,还是不行

提示都说了UserService.java第三十行有问题,你直接debug是哪里为空了,我觉得不是注入问题,你贴代码出来吧

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
spring自动注入失败
启动没有报错,但是注入失败xxService的值为null。应该是哪里的问题搞了一下午都没有解决。。。
Spring Boot JdbcTemplate
从零开始学Spring Boot视频教程,该课程主要讲解Spring Boot技术,理论+实战、一步一步带你入门 。《Spring Boot 自定义Starter 》3节;《Spring Boot WebSocket单聊+群聊》6节;《Spring Boot MyBatis 注解篇》12节;《Spring Boot MyBatis XML篇》 8节。
spring jdbcTemplate 注入到servlet
NULL 博文链接:https://dxflygao.iteye.com/blog/525010
Spring boot +jdbctemplate
Spring boot,事物,拦截器,servlet 自动装配,数据源
Spring 自动注入失败异常
在DAO层中使用了HibernateTemplate注入 报错信息如下 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerDao': Injection of autowired dependencies failed; nested except...
Spring Boot @Autowired 没法自动注入的问题
Application 启动类: @SpringBootApplication @EnableConfigurationProperties @ComponentScan(basePackages = { "com.testing"}) public class Application { @Bean RestTemplate restTemplate() { ret
spring boot自动注入找不到类
如果引用的类所在的包和使用的类不在一个包里,需要加ComponentScan @ComponentScan(basePackages = {&quot;org.xxx.redis&quot;,&quot;com.ddz.hintlightserver&quot;}) 另外,如果使用new的话,类里field都不可以自动注入了。 ...
Spring Boot无法自动注入bean问题解决方案
前言:在使用Spring Boot+Mybatis时,写完Mapper接口、Service、Controller后,启动(图1)打包项目(图2)均失败,提示无法自动注入bean。完成目标:1、无法自动注入bean错误信息2、代码展示3、解决方案一、错误信息:Description:Field userMapper in com.openplat.system.service.UserService...
Spring将子类自动注入父类失败
```rn@Controllerrnpublic class LoginControllerrnrn @Resource(name="loginService")rn private IService loginService;rn rn @RequestMapping("/login")rn @Autowiredrn public ModelAndView index(BaseClassDo logindo)rn LoginDo ll= (LoginDo) logindo;rn ModelAndView mv = new ModelAndView();rn System.out.println(logindo);rn// mv = loginService.doService(logindo);rn mv.setViewName("login");rn return mv;rn rnrn```rn上面index方法中,初始化的时候使用断点显示logindo是自动注入成功的,显示的是子类的字段,但是之后从页面jsp跳转过来后,注入失败,显示的只有父类的两个字段,而且强转失败java.lang.ClassCastException,难道从前台传到后天还有什么讲究吗rn使用@autowrie或@Resource都试过,没有用rn下面是实体表rnrn**父类**rn```rnpublic class BaseClassDo rn /**rn * 业务类型rn */rn private String ywtype;rn /**rn * 业务状态rn */rn private String ywstate;rn rn getset方法略rn```rn**子类**rn```rnrn@Component("loginDo")rnpublic class LoginDo extends BaseClassDo rn private String job_id;rn private int worker_id;rn private String login_pw;rn private String worker_name;rn rn getset方法略rn```
java反射导致spring自动注入失败
这个地方困扰了我很久,一直没有找到答案,网上的一些回答都只是小片段很是让人为难,这里记录一下自己的解决方式,免得以后忘记。首先我的spring 的bean是我通过扫描包的方式来自动注入的(com.spring.service是我的包名)&amp;lt;context:component-scan base-package=&quot;com.spring.service&quot; /&amp;gt;正是因为我是通过扫描的方式,故只...
spring boot项目依赖spring mvc项目注入失败问题
maven使用不同框架搭建的不同项目 项目1:spring boot搭建的war项目(这是maven的聚合项目) 项目2:spring mvc搭建的jar项目(这也是maven的聚合项目,核心项目) war项目将jar项目依赖进来 项目是spring boot配置 @SpringBootApplication public class Application extends Spring
spring 注入失败报错
报错代码片段: Error creating bean with name 'itemServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire...
spring bean 注入失败
1.异常信息 2.有可能引起的原因: 1.在applicationContext-service.xml的配置文件里的包扫描不对 2.在web.xml里没有加载spring容器 3.分布式工程,使用dubbo通信,在服务层,或者消费层, 单词写错了 4.还有一种可能,有可能是pom 里的jar包冲突 当时我看了这些就去解决,但是都无效 这个异常属于bean创建异常,原因是我的xml的路径设...
autoware自动注入失败
注入失败,个人总结 有这么几点, 1:spring 配置文件没有扫描包 检查下有没有这句 2:你的被注入的类有没有被spring管理 也就是有没有加注解, 3,:还有一点是一般新手可能遇到的,就是给servlet注入,这点和第二点是一样的,就是servlet不是被spring管理的,而是被tomcat或者其他服务器容器管理的,两者使用的不是同一个对象,这时,如果需要在你的servlet中使用
@autowired自动注入失败
Error creating bean with name 'employeeServiceImpl': Unsatisfied dependency expressed through field 'empMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.hdd.mapper.EmployeeMapper' available: ...rn怎么改啊?
spring 注入失败
web.xmlrnrnrn rn contextConfigLocationrn classpath:applicationContext-*.xmlrn rn rn org.springframework.web.context.ContextLoaderListenerrn rn rn dispatcherServletrn org.springframework.web.servlet.DispatcherServletrn rn contextConfigLocationrn /WEB-INF/profiles/applicationContext.xmlrn rn 1rn rn rn dispatcherServletrn *.dorn rnrnrn CloudServpagern rn index.htmlrn index.htmrn index.jsprn default.htmlrn default.htmrn default.jsprn rnrnrnapplicationContext.xmlrnrnrn rn rn rn org.springframework.web.servlet.view.JstlViewrn rn rn /WEB-INF/web/rn rn rn .jsprn rn rnrn rn rn rn rn loginActionrn loginActionrn loginActionrn loginActionrnrn roleActionrn roleActionrnrn houseActionrn houseActionrn houseActionrn rn rnrn rnrn rn rn rn rnrnrnrnapplicationContext-ibatis.xmlrnrnrnrnrn rn rn rn java:comp/env/jdbc/CloudServpagern rn rnrn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rn rnrnrnrn rn rn rn rn rn rn classpath:springSqlMapConfig.xmlrn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnapplicationContext-beans.xmlrnrnrn rn rn rnrn rn rn rn rnrn rn rn rn rnrnrnrnrn以上是我的spring配置文件rn下面是action 使用 对象时,发现对象没有注入,HouseBusiness为null。rnpublic class LoginAction extends MultiActionController rnrn private HouseBusiness housebusiness;rn rn public HouseBusiness getHousebusiness() rn return housebusiness;rn rnrn public void setHousebusiness(HouseBusiness housebusiness) rn this.housebusiness = housebusiness;rn rnrnibatis也注入失败rn严重: Servlet.service() for servlet dispatcherServlet threw exceptionrnjava.lang.IllegalArgumentException: No SqlMapClient specifiedrn
spring 注入失败!!!!!!!!
applicationContext.xmlrn[code=XML]rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rnstruts.xmlrn[code=XML]rnrn rn rn rn rn rn rn[/code]rnloginAction.xmlrn[code=XML]rn rn rn rn /sendSuccss.jsprn rn rn rn[/code]rnweb.xmlrn[code=XML]rn rn contextConfigLocationrn rn /WEB-INF/applicationContext*.xmlrn rn rn rn org.springframework.web.context.ContextLoaderListenerrn rn[/code]rnUserServiceImpl.javarn[code=Java]rnpublic class UserServiceImpl implements UserService rn public UserDAO userDao;rnrn public UserDAO getUserDao() rn return userDao;rn rnrn public void setUserDao(UserDAO userDao) rn this.userDao = userDao;rn rn[/code]rnrn[code=Java]rnpackage com.quxiuna.struts.action.login;rnrnimport java.util.Map;rnrnimport com.opensymphony.xwork2.ActionContext;rnimport com.opensymphony.xwork2.ActionSupport;rnimport com.quxiuna.hibernate.po.RbacUser;rnimport com.quxiuna.service.UserService;rnimport com.quxiuna.util.Constants;rnrnpublic class LoginAction extends ActionSupport rn rn private static final long serialVersionUID = -1640288447822607013L;rn rn private String name;rn private String password;rn private String message;rn public UserService userService;rnrn public String getName() rn return name;rn rn rn public void setName(String name) rn this.name = name;rn rnrn public String getPassword() rn return password;rn rnrn public void setPassword(String password) rn this.password = password;rn rn rn @SuppressWarnings("unchecked")rn public String execute() rn RbacUser user = userService.login(name, password);rn if (user != null) rn ActionContext ctx = ActionContext.getContext(); rn Map session = ctx.getSession(); rn session.put(Constants.SESSSION_NAME, name);rn return SUCCESS;rn else rn message = "用户名或密码错误!"; rn return ERROR;rn rn rnrn public String getMessage() rn return message;rn rnrn public void setMessage(String message) rn this.message = message;rn rnrn public UserService getUserService() rn return userService;rn rnrn public void setUserService(UserService userService) rn this.userService = userService;rn rnrn[/code]rnrn报错rnjava.lang.NullPointerExceptionrn com.quxiuna.struts.action.login.LoginAction.execute(LoginAction.java:38)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn java.lang.reflect.Method.invoke(Unknown Source)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)rn …………………………………………rn …………………………………………
Sping Boot注入接口失败
![图片说明](https://img-ask.csdn.net/upload/201804/21/1524291637_361310.png)n项目结构应该是正确的。nn```n@Repositorynpublic interface UserDao n n public User getById(int id);nn n```nDao层的代码,使用接口。n@Servicen```n@Servicenpublic class UserService n n @Autowiredn UserDao userDao;n n public User getById(int id) n return userDao.getById(id);n n n nn n```nservice层代码。nncontroller层注入service。nn启动spring boot后会提示dao层没有扫描到,如果@ComponentScan dao层的话,会提示service层注入失败,求解。nnnnnn
Spring 注入失败的原因
有一次写代码如下   ApplicationContext ctx = new ClassPathXmlApplicationContext(&quot;beans.xml&quot;);  HarborBusiness service = (HarborBusiness) ctx.getBean(&quot;harborBusiness&quot;);   总是报no bean named   查了半天没查出来了,后来把前一...
Spring @Autowired注入失败
今天做项目的时候出现了个问题,异常简要信息如下rn[code=java]Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.yuansheng.jst.permission.service.IPermissionService] is defined: expected single matching bean but found 2: permissonService,IPermissionService[/code]rn接口:rn[code=java]public interface IPermissionService rn[/code]rn实现类:rn[code=java]@Servicernpublic class PermissonService implements IPermissionService rn @Autowiredrn private PermissionMapper permissionMapper;rn rn[/code]rn控制器rn[code=java]@Controllerrn@Path("/permission")rn@Consumes(MediaType.APPLICATION_FORM_URLENCODED)rn@Produces(MediaType.APPLICATION_JSON)rnpublic class PermissionResource rn private Logger logger = Logger.getLogger(this.getClass());rn @Autowiredrn private IPermissionService permissionService;rnrn[/code]rnrn之前一直是这么注入的,没想到会出错,仔细检查后发现是由于实现类的名称中少写了一个字幕i导致的,即PermissionService写成了PermissonService,修改后就正确了。rn那么问题来了,@AutoWired默认是byType注入的,即使我的类名写错,接口也只有一个实现类,为什么会注入失败?而且异常信息是扫描到了两个可注入的类,其中一个还是IPermissionService,那么如果我实现类的名称写正确的话,为什么就能正确注入了,而没有扫描到两个?
@Resource注入spring失败
普通的class中的代码rn1、@Resourcern private AdBannerService bannerService;rnrnAdBannerService为接口 提供了AdBannerServiceImpl实现类rnrn2、spring的配置:是一次性把整个包都注入的rn[color=#FF0000] rn [/color]rn运行List adBanners=bannerService.adBannerList();rn就会报NullpointException错误,框架是SSI的rn不知道为什么会注入失败?求解!rnrn rn
Spring Boot打包失败
异常显示:[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.0.RELEASE:repackage (default) on project technicalInnerReference: Execution default of goal org.springframewor...
报错处理----JdbcTemplate空值之springmvc自动注入
1.报错信息    七月 06, 2018 6:57:56 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [springmvc] in context with path [/springmvc] threw exception [Request processin...
JdbcTemplate自动注入的时候出现空指针异常
JdbcTemplate自动注入的时候出现空指针异常UserDao.class@Autowired private JdbcTemplate jdbcTemplate;JUintTest@Test public void testCount(){ UserDao userDao = new UserDao(); long count = userDao
Springboot无法自动注入JdbcTemplate,非maven
注意了,我没有用到maven,也没有pom.xml文件。需要的jar包我都是自己导进项目的。rn在dao层配置注解rn[code=java]rn@Repository("wxDao")rnpublic class WxDaoImpl implements WxDao rn @Autowired rn private JdbcTemplate jt;rn rn @Overridern public List> getUserList() rn // TODO Auto-generated method stubrn String sql="select * from userTable";rn System.out.println("success");rn return null;rn rnrn[/code]rn启动入口类,报错找不到JdbcTemplate的bean,主要报错如下rn[code=java]rn2018-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)rn2018-03-22 16:21:25.226 INFO 10860 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcatrn2018-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:rn java.lang.Object.wait(Native Method)rn java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)rn com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)rn2018-03-22 16:21:25.254 INFO 10860 --- [ main] utoConfigurationReportLoggingInitializer : rnrnError starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.rn2018-03-22 16:21:25.398 ERROR 10860 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : rnrn***************************rnAPPLICATION FAILED TO STARTrn***************************rnrnDescription:rnrnField jt in com.weapp.dao.impl.WxDaoImpl required a bean of type 'org.springframework.jdbc.core.JdbcTemplate' that could not be found.rn - Bean method 'jdbcTemplate' not loaded because @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) did not find any beansrnrnrnAction:rnrnConsider revisiting the conditions above or defining a bean of type 'org.springframework.jdbc.core.JdbcTemplate' in your configuration.rn[/code]rn配置文件数据库相关配置rn[code=java]rn###### dbsource###### rnspring.datasource.url=jdbc:mysql://localhost:3306/wxapp rnspring.datasource.username=root rnspring.datasource.password=sql12345 rnspring.datasource.driver-class-name=com.mysql.jdbc.Driverrn[/code]rn这个问题卡了很久,求解答
从零开始学Spring Boot视频
【从零开始学Spring Boot】已经在ITeye进行发布了, 【Spring Boot 系列博客】   0)前言【从零开始学Spring Boot】 : http://412887952-qq-com.iteye.com/blog/2291496   (1)spring boot起步之Hello World【从零开始学Spring Boot】: http://4128
Spring Boot 学习笔记(八)——SQL之JdbcTemplate
哎,学不下去了,明天再来吧 于2018-10-29-19:21…
Spring boot JdbcTemplate使用多数据源配置
注:使用上篇的Mac Spring boot(1.5.9) 使用JDBCTemplate操作数据库,现在我们使用两个数据库,都有个user表,对user表进行相关数据库操作1、看下项目目录 2、我们配置下application.properties,连接的两个数据库new_schema和new_testspring.datasource.primary.url =jdbc:mysql://loca
Spring boot使用JdbcTemplate进行数据操作
步骤一:编写Dao,并加上@Repository注解进行声明步骤二:service层步骤三:Controller层步骤四:访问测试走起
9. 使用JdbcTemplate【从零开始学Spring Boot】
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2291574
Spring Boot(三):JDBCTemplate对数据表的增删改查
数据表的增删改查是基本操作,springboot中第一次接触,操作原理都是一样的。就是spring对jdbc的封装模版   1、实现类 @Service public class UserServiceImpl { @Autowired private JdbcTemplate jdbcTemplate; //select public List...
spring boot用jdbctemplate连接数据库,启动报错
错误信息:rnjava.lang.TypeNotPresentException: Type org.springframework.test.context.ContextConfiguration not presentrn at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:46) ~[na:1.8.0_151]rn at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:84) ~[na:1.8.0_151]rnjava.lang.ClassNotFoundException: org.springframework.test.context.ContextConfigurationrnrn----------------------------------------------------------------------------------------------------------------------------------------------------------------------------rn代码:rn[b]Application类:[/b]rnpackage com.weibo.dip;rnimport org.springframework.boot.SpringApplication;rnimport org.springframework.boot.test.SpringApplicationConfiguration;rnrn@SpringApplicationConfiguration(Application.class)rnpublic class Application rnrn public static void main(String[] args) rn SpringApplication.run(Application.class);rn rnrnrn[b]Cotroller类:[/b]rnpackage com.weibo.dip.controller;rnrnimport com.weibo.dip.bean.Dataset;rnimport com.weibo.dip.service.DatasetService;rnimport com.weibo.dip.serviceImpl.DatasetServiceImpl;rnimport org.springframework.beans.factory.annotation.Autowired;rnimport org.springframework.boot.autoconfigure.EnableAutoConfiguration;rnimport org.springframework.web.bind.annotation.RequestMapping;rnimport org.springframework.web.bind.annotation.RestController;rnrnimport javax.annotation.Resource;rnrn@RestControllerrn@EnableAutoConfigurationrn@RequestMapping("/demo2")rnpublic class Controller rnrn @Resourcern private DatasetServiceImpl datasetService;rnrn public void setUp() rn // 准备,清空user表rn datasetService.deleteAllUsers();rn rnrn @RequestMapping("/save")rn public void test() throws Exception rn // 插入5个用户rn datasetService.create(1);rn datasetService.create(2);rn datasetService.create(3);rn datasetService.create(4);rn datasetService.create(5);rn rnrn @RequestMapping("/getById")rn public Dataset getById(int id)rn return datasetService.findDatasetById(id);rn rnrn
Spring Boot多数据源(JdbcTemplate)配置与使用
https://blog.csdn.net/u012081441/article/details/80746538
Spring Boot中使用JdbcTemplate访问数据库
一 数据源的配置 1 pom中引入JDBC的支持 &amp;lt;dependency&amp;gt; &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt; &amp;lt;artifactId&amp;gt;spring-boot-starter-jdbc&amp;lt;/artifactId&amp;gt; &amp;lt;/dependency&amp;gt; 2 关于嵌入...
Spring boot配置文件值注入
@ConfigurationProperties 将配置文件中配置的每一个属性的值,映射到这个组件中 告诉SpringBoot将本类中的所有属性 和配置文件中相关的配置进行绑定 Prefix 表示前缀,配置文件中哪个 下面的所有属性进行一一映射 注意 只有这个组件是容器中的组件 才能容器使用提供的@ConfigurationProperties功能 使用注解,这个组件必须在容器...
spring boot 静态变量注入配置文件
spring 静态变量注入spring 中不支持直接进行静态变量值的注入,我们看一下代码:@Component(value = "KafkaConfig") @ConfigurationProperties(prefix = "baseConfig") public class KafkaConfig { private static String logBrokerList; public sta
Spring自动注入
注意,注入的是bean标签下property的name与另一个beasn的id相同时,可以省略 例如当spring整合mybatis时 &amp;amp;amp;lt;bean id=&amp;amp;quot;dataSource&amp;amp;quot; class=&amp;amp;quot;org.springframework.jdbc.datasource.DriverManagerDataSource&amp;amp;quot;&amp;amp;amp;gt; &amp;
Spring 自动注入报错
哪位大侠给瞅瞅啊rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: richeninfo.dao.UserMapper richeninfo.service.UserService.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [richeninfo.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rnRelated cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\sts\configSystem\target\classes\richeninfo\dao\UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\sts\configSystem\target\classes\richeninfo\mapping\UserMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum const class org.apache.ibatis.type.JdbcType.Integerrn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)rn at richeninfo.test.UserTest.findUser(UserTest.java:24)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)rn at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)rn at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:309)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: richeninfo.dao.UserMapper richeninfo.service.UserService.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [richeninfo.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)rn ... 36 morernCaused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [richeninfo.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:949)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)rn ... 38 morernRelated cause:rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\sts\configSystem\target\classes\richeninfo\dao\UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\sts\configSystem\target\classes\richeninfo\mapping\UserMapper.xml]'; nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum const class org.apache.ibatis.type.JdbcType.Integerrn at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)rn at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1391)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getTypeForFactoryBean(AbstractBeanFactory.java:1357)rn
Spring自动注入“失效”
spring的bean被织入切面后,直接访问他的成员变量,会得到null值。 最糟糕的是不会有任何报错,很难发现。 这个问题的真正原因是,spring的AOP基于动态代理实现,也就是说我们拿到的bean的class不是他本身的class,而是spring自动生成的一个代理对象。//比如我们有这样一个类 public final class HelloMessage { //我们期望这个
Spring自动注入byType
**1.applicationContext.xml配置文件** <!-- 配置dao层bean --> <bean id="edi" class="dao.impl.EmpDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> //
相关热词 c# 去空格去转义符 c#用户登录窗体代码 c# 流 c# linux 可视化 c# mvc 返回图片 c# 像素空间 c# 日期 最后一天 c#字典序排序 c# 截屏取色 c#中的哪些属于托管机制