草庐IT

Bean-IOC

全部标签

java - Caused by : java. lang.IllegalStateException : Ambiguous mapping found. Cannot map 'appController' bean method

大家早上好,我正在处理一个我无法解码的模糊映射...我正在使用Springmvc4.0.6和hibernate4.3.6在tomcat中发起war时出现此错误:ERROR[localhost-startStop-2]:Contextinitializationfailedorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'requestMappingHandlerMapping'definedinclassorg.springframework.web.servlet.con

java - 将请求范围的 bean 注入(inject)另一个 bean

我想创建一个在请求生命周期中唯一的UUID。为此,我创建了一个带有@Scope("request")注释的UUIDbean。@Bean@Scope(scopeName=WebApplicationContext.SCOPE_REQUEST)publicUUIDrequestUUID(){returnUUID.randomUUID();}我想在我的Controller中访问这个bean。所以我用@Autowired注入(inject)它。这很好用。@ControllerpublicclassDashboardController{@AutowiredUUIDuuid;@Autowired

java - 创建名称为 'sessionFactory' 的 bean 时出错 : MalformedParameterizedTypeException

我们将不胜感激任何建议。我很难过...问题在我的笔记本电脑上,每当我们的应用程序尝试加载application-config.xml时,我都会收到java.lang.reflect.MalformedParameterizedTypeException。完全相同的代码适用于我的台式机和我同事的台式机/笔记本电脑。但是在我的笔记本电脑上它抛出了这个错误。由于我的笔记本电脑和台式机是完全相同的开发环境(MacOSXLeopard上Eclipse中的Java1.6Maven项目),我通过执行以下操作缩小了原因范围:从Subversioncheckout一个新项目(因此没有代码差异)复制并替换

java - 我如何了解运行时是否存在 bean?

比如我有一个类publicclassCar{privateMotormotor;publicvoidsetMotor(Motormotor){this.motor=motor;}}我的bean看起来像此方法:motorProvider.getAvailableMotor()返回一个bean名称(字符串),我应该使用其中的电机。但是可能会出现这样的bean(具有这样的名称)没有被创建的情况。如何检查? 最佳答案 有几种模式可以做到这一点。这是我经常使用的一个:publicclassCar{privateMotormotor;@Auto

java - JavaConfig 中的 Spring Bean 别名

我有一个带@Service注释的类,它提供了我可以在所有项目中使用的核心功能:@ServicepublicclassMyService{}另一个扩展它以实现项目特定的东西:@ServicepublicclassExtendedMyServiceextendsMyService{}现在我想配置一个bean别名,以便在使用属性Autowiring它时能够使用@Qualifier("MyServiceAlias"):#MyServicequalifier(default:myService)myService.qualifier=extendedMyService在XML中它看起来像:也讨论

java - 没有定义类型的唯一 bean : expected single matching bean but found 2

这个问题在这里已经有了答案:WhatisaNoSuchBeanDefinitionExceptionandhowdoIfixit?(1个回答)关闭6年前。我在部署代码时遇到以下异常Causedby:org.springframework.beans.factory.NoSuchBeanDefinitionException:Nouniquebeanoftype[com.belk.api.adapter.contract.Adapter]isdefined:expectedsinglematchingbeanbutfound2:[endeca,solar]atorg.springfram

java - BeanUtils 与 ReflectionToStringBuilder 的性能对比(用于 Bean 类)

我的Web应用程序中有大量Javabean类,我正试图找到一种简单的方法来在这些bean中实现toString()方法。toString()方法将用于记录整个应用程序,并且应该打印bean中所有属性的属性值对。我正在尝试两种选择:1.BeanUtils.describe()(Apachecommons-beanutils)2.ReflectionToStringBuilder.toString()(Apache通用语言)由于这是一个预期具有高流量的Web应用程序,因此实现必须是轻量级的,并且不应影响性能。(内存使用、处理器使用等是主要考虑因素)。我想知道根据上述标准,其中哪些表现更好。

java - Spring ThreadPoolExecutor Factory Bean工厂bean的使用方法

我希望能够将ExecutorService实例注入(inject)到我的Spring服务中,SpringAPI建议为此目的使用ThreadPoolExecutorFactoryBean。很简单的问题;我到底该如何使用ThreadPoolExecutorFactoryBean创建一个可以连接到其他服务的ExecutorService?问他的问题我觉得自己像个白痴,但我似乎无法弄清楚这个问题。 最佳答案 展开skaffman'sanswer,这是一个简短而贴心的例子,说明需要做什么:再次,请参阅JavaDocs有关可以设置以配置Exec

java - Spring - 创建 Bean 时出现奇怪的错误

知道为什么我会收到此异常吗?Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'myService'definedinclasspathresource[context.xml]:Initializationofbeanfailed;nestedexceptionisorg.springframework.beans.TypeMismatchException:Failedtoconvertpropertyvalueoftype[$Proxy54implem

SpringBoot 源码解析7:Bean的创建② AbstractAutowireCapableBeanFactory#createBean

SpringBoot源码解析7:Bean的创建②AbstractAutowireCapableBeanFactory#createBean1.概述2.单例Bean的创建2.1DefaultSingletonBeanRegistry#getSingleton3.createBean源码4.AbstractAutowireCapableBeanFactory#doCreateBean源码5实例化Bean-AbstractAutowireCapableBeanFactory#createBeanInstance6推断构造器7.instantiateBean实例化Bean8.AbstractAutow