草庐IT

autowiring

全部标签

java - 可以弹出@Autowired Map吗?

这是map@AutowiredprivateMapconverters;和ISendableConverterpublicinterfaceISendableConverter{ISendableMsgconvert(BaseMessagebaseMessage);StringgetType();}有一些类实现了ISendableConverter我想通过使用spring@Autowried注释将它们注入(inject)到变量converters中。类的实例为value,方法getType()的结果为key。喜欢这个@ComponentpublicclassSendableVoiceM

java - 何时在 Spring 中使用 Autowiring

我正在看书ProSpring3.它有一段让我很困惑。这一段是关于Spring的Autowiring。摘录如下:Inmostcases,theanswertothequestionofwhetheryoushoulduseautowiringisdefinitely“no!”Autowiringcansaveyoutimeinsmallapplications,butinmanycases,itleadstobadpracticesandisinflexibleinlargeapplications.UsingbyNameseemslikeagoodidea,butitmayleadyo

java - 何时在 Spring 中使用 Autowiring

我正在看书ProSpring3.它有一段让我很困惑。这一段是关于Spring的Autowiring。摘录如下:Inmostcases,theanswertothequestionofwhetheryoushoulduseautowiringisdefinitely“no!”Autowiringcansaveyoutimeinsmallapplications,butinmanycases,itleadstobadpracticesandisinflexibleinlargeapplications.UsingbyNameseemslikeagoodidea,butitmayleadyo

java - spring @Autowire 属性与 setter

将@Autowired注释到属性或在setter中执行有什么区别?据我所知,它们都有相同的结果,但是有什么理由使用其中一个而不是另一个?更新(更简洁)这有区别吗packagecom.tutorialspoint;importorg.springframework.beans.factory.annotation.Autowired;publicclassTextEditor{privateSpellCheckerspellChecker;@AutowiredpublicvoidsetSpellChecker(SpellCheckerspellChecker){this.spellChe

java - spring @Autowire 属性与 setter

将@Autowired注释到属性或在setter中执行有什么区别?据我所知,它们都有相同的结果,但是有什么理由使用其中一个而不是另一个?更新(更简洁)这有区别吗packagecom.tutorialspoint;importorg.springframework.beans.factory.annotation.Autowired;publicclassTextEditor{privateSpellCheckerspellChecker;@AutowiredpublicvoidsetSpellChecker(SpellCheckerspellChecker){this.spellChe

java - 如果 Spring 中没有 bean,是否有一种简单的方法来 Autowiring 空集合?

如果我有@AutowiredListbeans;没有SomeBeanClass的bean,我得到:Nomatchingbeanoftype[SomeBeanClass]foundfordependency[collectionofSomeBeanClass]:expectedatleast1beanwhichqualifiesasautowirecandidateforthisdependency.Dependencyannotations:{@org.springframework.beans.factory.annotation.Autowired(required=true)}如

java - 如果 Spring 中没有 bean,是否有一种简单的方法来 Autowiring 空集合?

如果我有@AutowiredListbeans;没有SomeBeanClass的bean,我得到:Nomatchingbeanoftype[SomeBeanClass]foundfordependency[collectionofSomeBeanClass]:expectedatleast1beanwhichqualifiesasautowirecandidateforthisdependency.Dependencyannotations:{@org.springframework.beans.factory.annotation.Autowired(required=true)}如

Spring拦截器的Java配置,其中拦截器使用 Autowiring 的spring bean

我想将springmvc拦截器添加为Java配置的一部分。我已经有一个基于xml的配置,但我正在尝试迁移到Java配置。对于拦截器,我知道可以从spring文档中这样完成-@EnableWebMvc@ConfigurationpublicclassWebConfigextendsWebMvcConfigurerAdapter{@OverridepublicvoidaddInterceptors(InterceptorRegistryregistry){registry.addInterceptor(newLocaleInterceptor());}}但是我的拦截器正在使用一个Autow

Spring拦截器的Java配置,其中拦截器使用 Autowiring 的spring bean

我想将springmvc拦截器添加为Java配置的一部分。我已经有一个基于xml的配置,但我正在尝试迁移到Java配置。对于拦截器,我知道可以从spring文档中这样完成-@EnableWebMvc@ConfigurationpublicclassWebConfigextendsWebMvcConfigurerAdapter{@OverridepublicvoidaddInterceptors(InterceptorRegistryregistry){registry.addInterceptor(newLocaleInterceptor());}}但是我的拦截器正在使用一个Autow

Spring Autowiring 列表

是否可以将@Autowired与列表一起使用?就像我有带有mimetypes的属性文件,在我的类文件中我有这样的东西@AutowiredprivateListmimeTypes=newArrayList(); 最佳答案 Spring4及更早版本支持自动收集给定类型的所有bean并将它们注入(inject)到集合或数组中的能力。这是一个例子:@ComponentpublicclassCarimplementsVehicle{}@ComponentpublicclassBusimplementsVehicle{}@Componentpu