草庐IT

Autowiring

全部标签

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 中没有 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

Spring Autowiring 列表

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

java - Autowiring 同一类的两个不同的bean

我有一个封装了一个连接池的类,该类从一个spring配置中获取它的连接细节,如下所示:此bean稍后在服务中使用,并使用@Autowire注释Autowiring。我的问题是,我怎样才能复制这个bean并给它不同的连接细节,然后在服务中@Autowire它。意思除了上面我还有:在服务中:@Autowired//beanofidjedisConnectorJedisConnectorbeanA;@Autowired//beanofidjedisConnectorPODJedisConnectorbeanB; 最佳答案 您可以将@Aut

java - Autowiring 同一类的两个不同的bean

我有一个封装了一个连接池的类,该类从一个spring配置中获取它的连接细节,如下所示:此bean稍后在服务中使用,并使用@Autowire注释Autowiring。我的问题是,我怎样才能复制这个bean并给它不同的连接细节,然后在服务中@Autowire它。意思除了上面我还有:在服务中:@Autowired//beanofidjedisConnectorJedisConnectorbeanA;@Autowired//beanofidjedisConnectorPODJedisConnectorbeanB; 最佳答案 您可以将@Aut