Spring 注入错误,求解

以前我们的项目就一个单独的项目文件,现在需要把项目拆分,于是我就想把bean dao service抽出来做成jar包来导入到拆分后的各个项目中,但是出现了问题

我们的项目是使用struts2+Spring+Hibernate,使用了Spring的注解,现报错如下.
[code="java"]
[2011-01-07 16:36:04,346]-INFO (JCLLoggerAdapter.java:262)|schema update complete
[2011-01-07 16:36:05,786]-INFO (JCLLoggerAdapter.java:262)|closing
[2011-01-07 16:36:05,847]-ERROR (ContextLoader.java:220)|Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
... 37 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:903)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:772)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:686)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:431)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
... 50 more
2011-1-7 16:36:05 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
... 37 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:903)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:772)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:686)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:431)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
... 50 more
2011-1-7 16:36:05 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2011-1-7 16:36:05 org.apache.catalina.core.StandardContext start
严重: Context [/Fohome] startup failed due to previous errors
2011-1-7 16:36:05 org.apache.catalina.core.ApplicationContext log
[/code]

百思不得其解,求各位高手相救

0

11个回答

用其他方式生成这个jar试试,不要用eclipse的工具。

0
csjxhx
csjxhx 正解啊 折腾1天多的这个问题终于解决了 用eclipse打的jar包不行啊 maven打的包可以 谢谢
6 年多之前 回复

[code="java"]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
[/code]

应该是你要注入一个
com.fohome.front.dao.NewsDao
类型的对象,但通过注解注入却找不到已定义的NewsDao类型的Bean

0

在com.fohome.front.dao.NewsDao加一个注解@Repository,如果com.fohome.front.dao.NewsDao是接口,就在其中一个实现类加。

0

[quote]已经加了,问题是,这个类放在项目里面就没有问题,但是抽取出来放到jar包里就找不到,相当郁闷 [/quote]
[code="xml"][/code]
这个配置没问题吧?

0

[quote]应该没什么问题吧,以前也没有什么问题,现在把newsDao放到外部的jar中,就不行了[/quote]

觉得这个jar在运行时的classpath中?

0

[quote]请问是什么意思?[/quote]

只是问问,以确定你没有忘了把那个jar放到项目的发布环境中了。

0

[quote]jar里面的bean是可以用的,但是dao不行[/quote]

不是不能启动吗?

0

[quote]我的QQ是18478180[/quote]
下班了,不上网。 下周一还没解决,再说啦,呵~

0

你是不是打包成jar放到web项目里的时候报错?
如果是,那就看看你打的jar包里有没有spring的配置文件。
希望能够管用。

0

我也遇到这样的情况的,采用的spring mvc + jpa的架构,用maven管理,
每个entity实体类作为一个maven工程,里面有dao,entity,service,serviceimpl,
在spring mvc中只有controller了,依靠maven导入entity的maven工程,
然后调用service,现在不知道怎样配置。

如果有朋友知道怎么配置,麻烦告诉我,谢谢哦,我也非常愿意和你进行交流:
QQ 1019990976
Email 1019990976 at qq.com

0
xigua366
xigua366 你要到tomcat发布目录下用压缩工具打开jar包看看,生成的jar包是否正常
接近 6 年之前 回复
共11条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
自定义类型转换器解决Spring配置文件注入类型错误的问题 PropertyEditorSupport
1.场景 假设我们有一个Bean其中有一个属性为Date类型,我们通过配置文件配置其值为"2017-12-18" 注入到Spring的容器中后会报错 因为配置文件中的类型都默认为 String类型,而Bean中的类型为Date类型,因而直接注入会报错 这时可以通过实现自己的属性转化策略来实现从BeanDefinied转成Bean时进行一些附加的处理来帮助我们将String类型日期转化为Dat
记录一次spring以构造器方式进行依赖注入的错误
自己的代码如下:(MVC模式) 我的文档结构图: 这是主测试类: package com.gzz.spring04_DI; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; pu...
spring在构造器注入时报错,类型不匹配
====================================>User.java public class User { private Integer id; private String name; private Integer age;   public User(){} public User(Integer id, String name, Integ...
自动装配引起的Spring注入错误
当XML文件中添加了default-autowire="byName"时,会自动为属性注入同名的bean实例,即使为该属性显式指定了一个ref也不生效。 以上配置文件中,其实两个数据库的操作类操作的数据源都是DB_100。因为其实updateBDbUse
spring的三种注入方式
spring 注入 spring 注入 spring 注入 spring 注入
关于spring的面试题
Spring AOP相关的几道面试题 1. 说出Spring的通知类型有哪些? 2. 谈谈目标对象实现接口与目标对象不实现接口有什么区别? 3. 请描述JDK动态代理和CGLI代理的区别? 4. 简述ProxyFactoryBean的作用是什么? 5. 叙述Spring中的自动代理的原理? 5. 写出创建代理对象需指定的三要素是什么? 6. 写出代理的两种方式分别是什
spring重复注入爬坑
在整合RabbitMQ时遇到了spring的属性注入无效的问题,配置问题处如下: <!--声明生产者 --> <bean id="messageSender" class="com.trace.app.framework.services.MessageSender" name="MessageSender"&...
Spring Boot 单元测试,注入失败,报空指针错误
        今天写代码,在test的类中@Autowired注入要测试的@Component类,但发现一运行就会报空指针异常java.lang.NullPointException,但发现使用new的方法的时候可以注入这个@Component类,但是要调用这个@Component中注入的其他的类时也会报空指针异常,在网上查了很多,比如说在idea软件里test的目录是在src下,但是都没有解决...
在Resource中自动注入出错问题解决
编写代码的时候出现了,这个问题,这个报错,看到一条红线。发现上面引包并没有出现错误,然后我就用了idea的快捷键引包,发现也并没有出现缺失包的情况。所以断定应该是系统编译的问题。用鼠标点击或者用idea的快捷键,显示出错误,我用鼠标点击,出现Could not autowire. No beans of 'xxxx' type found提示,我试着查看下是否是xml的错误打开xml后发现,并没有...
Intellij IDEA 中 Spring 自动注入总是报错(Error) 的解决办法
在此处,将 Error 改成 Warning 即可:
Spring 依赖注入三种方式的实现,及循环依赖问题的解决(源码+XML配置)
  搬砖啦,搬砖啦,这几天在看Spring相关的书,下面给大家分享一下这几天的心得与收获,Go Go Go! Spring支持两种依赖注入方式,分别是属性注入,构造函数注入。除此之外,Spring还支持工厂注入方式。 接下来,我们一起来了解一下Spring的几种注入方式。 一.属性注入 首先来了解一下定义:属性注入是指通过 setXxx()方法注入Bean的属性或依赖对象。 为什么要使...
Spring Dao使用自动注入配置错误小记
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" org.springfra
SpringBoot新手入门一直显示Bin注入错误
java新手 刚接触SpringBoot 都是复制别人的Demo  在别人的项目里面能跑在自己这为什么不行? 我是复制的测试类的时候把包也复制过来 覆盖原来的名字  因为测试类的文件结构,保持src/test/java和src/main/java结构一直,即:包+文件夹。      如:com.example包service中类的测试,那么在src/test/java也是建立com.
【Ignite/Spring Boot】jar包运行出现依赖注入错误的反思
前段时间开发集成Ignite的Spring Boot时,遇到了一个非常棘手的问题。现在回想起来,还是应该在博客上做一个记录。 开发Spring Boot微服务,我用了Netbeans IDE(本科用习惯了,一直舍不得换,虽然感觉idea之类的IDE也是确实好用)。微服务开发完成后,在Netbeans上清理构建运行都没有任何问题。但是打包发送到服务器上,发现跑不起来,控制台输出了一大堆依赖注入错误...
解决springmvc时间注入的问题
import org.springframework.web.bind.ServletRequestDataBinder;import org.springframework.beans.propertyeditors.CustomDateEditor;@InitBinder protected void initBinder(HttpServletRequest request, Servlet...
Springboot 单元测试注解报错 或 注入失败
今天做单元测试遇到一个问题,报错信息如下: java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test at org.spr...
aop的xml文件配置
proxy-target-class="true" 与proxy-target-class="false"的区别:         proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。如果proxy-target-class属值被设置为false或者这
spring注入失败分析
问题阐述:   自动注入以实现类方式注入,启动报错: nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dimeng.p2p.common.repayment.service.RepaymentServiceImpl...
浅谈Service层为何要有接口
原文地址:https://www.cnblogs.com/chyu/p/6147907.html 浅谈Service层为何要有接口 被人随意问了一句,为何每个service层都要写一个接口呢,多麻烦~虽然想说点什么,但是又不知道从何说起,只好从新整理一下思绪. 情景1:在开源框架中有很多这种情况,就是某个功能支持用户自定义扩展.说白了,它提供了一个接口,我们只需要实现这个接口,把我们自己的实...
Spring注入失败原因
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error c...
SpringMvc中自动注入失败原因
在SpringMvc中使用自动注入并且给与bean的属性默认值的时候,刚开始tomcat启动报错bean的自动注入失败,后来自己使用@Qualifier使用ByName后Tomcat启动正常没有报自动注入失败的错误,但是在给属性赋予默认值出错,代码调用并没有赋值成功,返回的为null,让我很困扰,找了很久后,发现原因在配置文件中赋予默认值的配置中,如下: 问题处在bean的id上,原因就是i
关于spring@value注入配置文件值失败的原因
今天我写了一个system.propertities配置文件定义了一个变量host=localhost。 然后在spring 配置文件中加入了加载配置 在service中这样写 @Value("${host}") private static String host; 但是获取不到,各种查资料,最后发现是static关键字的原因 spring@Value依赖注入是依赖set方法 se...
解决spring boot websocket无法注入bean的问题
其实不是不能注入,是已经注入了,但是客户端每建立一个链接就会创建一个对象,这个对象没有任何的bean注入操作,下面贴下实践 接下来 解决办法就是springboot启动的时候注入一个static的对象
Spring根据XML配置文件注入对象类型属性
这里有dao、service和Servlet三个地方 通过配过文件xml生成对象,并注入对象类型的属性,降低耦合 dao文件代码: package com.swift; public class DaoUser { public void fun() { System.out.println("I'm dao's fun()..............
springMVC之spring容器注入失败的一种解决方案
HTTP Status 500 - Servlet.init() for servlet SpringDemo-dispatcher threw exceptionorg.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type '' available通用解决方法:如果是用xml...
struts2与spring整合时提示无法注入bean的错误
缺少struts2-spring-plugin.jar
kotlin依赖注入报错
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxServiceImpl' defined in file [xxxServiceImpl.class]: Unexpected exception during bean creation; ne...
spring中自动注入时 set 方法中的空指针异常
这种在注入map类型的testMap时,如果使用 setTestMap(String value){ this.testMap.put(value,value) }          会报空指针异常。 修改为   setTestMap(String value){ Map<String,String> tomap = new HashMap...
springboot配置文件注入失败,null值的问题
#静态配置文件 注入到方法中 ftp: ip: 127.0.0.1 port: 21 username: miny password: root #企业文化图片地址 company-culture-path: /company/culture/ #用户相关的图片地址 user-img-path: /user/img/ name: aaaa
spring2.5 注解依赖注入由于jdk1.8产生的问题
spring2.5的注解注入不支持jdk1.8,必须使用jdk1.5-jdk1.7的jre
Spring注入内部bean和使用命名空间p
Spring注入内部bean 内部bean 不用配置id属性 不能被复用,适用于一次注入 且不能被其他bean所引用 使用Spring 的命名空间p 装配属性
Spring的配置以及事件注入
Spring的配置以及事件注入Spring的配置以及事件注入Spring的配置以及事件注入
spring各种属性的注入
spring各种属性的注入 spring各种属性的注入 spring各种属性的注入
java反射导致spring自动注入失败
这个地方困扰了我很久,一直没有找到答案,网上的一些回答都只是小片段很是让人为难,这里记录一下自己的解决方式,免得以后忘记。首先我的spring 的bean是我通过扫描包的方式来自动注入的(com.spring.service是我的包名)<context:component-scan base-package="com.spring.service" />正是因为我是通过扫描的方式,故只...
Spring 整合 MyBatis,Mapper注入失败
出现问题,分析原因今天拿出在做的项目,启动运行,报错:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.liu.dao.UserInfoMapper] found for dependency: expected at least 1 bean which
Spring注入接口的实现类报错分析,dao无法注入
这里自我总结下一般注入报错问题可能情况:   1.dao实现类未添加注解@Repository  (或者添加bean配置,我本身一直不喜欢配置,所以基本没有使用配置,需要这种方式自行百度,我就不累赘)   2.实现多个实现未指定实现类,引入dao自动装配时(@Autowired)添加注解@Qualifaer(value="xxxx")指定实现类几种装配类型参考博客:https://www.cnbl...
springboot+dubbo注入service报错,找了全网也没找到答案
springboot+dubbo注入service错误
SpringJUnitTest使用Mockito无法正确注入Mock Bean的问题
Mock在注入的时候,对代理类无法注入,比如使用了AOP的类,可以使使用下面两种方式来解决: 借助spring-test的AopTestUtils和ReflectionTestUtils来完成mock bean的注入。此种方法需要使用spring-test的版本为5.0.2及以上,jdk为1.8及以上。 借助spring-aop的A...
springboot项目所有的注入报错,而且访问不到静态数据,报错302
检查代码是否有红线报错的地方。
spring对象注入失败问题
spring对象注入失败 问题描述 笔者在编写代码中,希望构建一个工具类,在工具类中需要访问dao层接口操作数据库。于是便想在工具类中注入一个mabatis的mapper接口。 代码片段 public class LogUtil { @Autowired private LogMapper logMapper; public static final Stri...