草庐IT

Bean-IOC

全部标签

spring - 为引用 session bean/原型(prototype) bean 的单例 bean 创建了多少个实例

我对下面提到的场景中使用SpringFramework时会创建的实例数量有疑问:bean配置是这样的or默认情况下,bean"a"有singletonscope.所以有一个单例bean引用具有session范围或原型(prototype)范围的bean。在这种情况下,如果有2个同时向应用程序发出请求,那么将创建多少个A实例和多少个B实例?如果有人能解释这是如何工作的,那将会有很大帮助。谢谢,迪维亚 最佳答案 单例范围当bean是singleton,将只管理bean的一个共享实例,并且所有对具有与该bean定义匹配的id或ids的be

java - 原型(prototype) Bean 没有按预期 Autowiring

TestController.java@RestControllerpublicclassTestController{@AutowiredprivateTestClasstestClass;@RequestMapping(value="/test",method=RequestMethod.GET)publicvoidtestThread(HttpServletResponseresponse)throwsException{testClass.doSomething();}}TestClass.java@Component@Scope("prototype")publicclass

java - 如果 bean 已经用 @ConfigurationProperties 注释,@EnableConfigurationProperties 有什么区别?

TheSpringBootdocumentation说要使用@ConfigurationProperties注释Youalsoneedtolistthepropertiesclassestoregisterinthe@EnableConfigurationPropertiesannotation,asshowninthefollowingexample:并给出以下代码:@Configuration@EnableConfigurationProperties(AcmeProperties.class)publicclassMyConfiguration{}但在下一段中说:Evenifth

security - 在父上下文与子上下文中声明 Spring Bean

我有一个springbean(dao)对象,我通过以下xml在我的ServletContext中实例化它:这个bean在我的webapp-servlet.xml文件中声明,并被我的应用程序在ServletContext中使用。我也在使用SpringSecurity。我的理解是它在不同的上下文(SecurityContext)中运行。我的应用程序有一个webapp-security.xml,我在其中实例化了一个自定义身份验证提供程序。我想使用我的应用程序中使用的dao来在我的安全上下文中进行用户查找,但是当我运行时:我收到错误消息,说没有这样的bean“userDao”。bean在我的其

java - 什么时候实例化一个spring bean

ApplicationContextctx=newClassPathXmlApplicationContext("com/springinaction/springidol/spring-idol.xml");Performerperformer=(Performer)ctx.getBean("duke");performer.perform();在上面,bean是什么时候实例化的,ApplicationContext是什么时候创建的,或者getBean()是什么时候被调用的? 最佳答案 假设bean是一个单例,并且没有配置为延迟初

java - 在非单例 bean 上的 Spring 代理上修复 BeanNotOfRequiredTypeException?

我在从应用程序上下文中提取Springbean时遇到问题。当我尝试时;InnerThreadinstance=(InnerThread)SpringContextFactory.getApplicationContext().getBean("innerThread",InnerThread.class);我明白了;org.springframework.beans.factory.BeanNotOfRequiredTypeException:Beannamed'innerThread'mustbeoftype[com.generic.InnerThread],butwasactual

java - 如何在spring中引用另一个xml文件的bean

我在xml文件中定义了一个Springbean。我想从另一个xml文件中引用它。我该怎么办? 最佳答案 你有几个选择:导入包含在ApplicationContext构造中在创建时将这两个文件都作为ApplicationContext的一部分=>然后不需要导入。例如,如果您在测试期间需要它:@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration({"classpath:META-INF/conf/spring/this-xml-conf.xml","classpath:

java - 使用注释创建原型(prototype)范围的 Spring bean?

是否可以转换以下XMLconfiguration到基于注释的?我正在使用Spring2.5.6. 最佳答案 您可以使用@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE)注释。@Service@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)publicclassCustomerService{//...}SpringAPIDocs.Exampleofthemapping.Scopeannotationreference.

java - spring security : NoSuchBeanDefinitionException: No qualifying bean of type [org. springframework.security.config.annotation.ObjectPostProcessor] 找到

我正在尝试将spring-security添加到我的休息应用程序中。我按照spring网站上的教程(https://spring.io/guides/tutorials/spring-security-and-angular-js/)来做,但是它使用了我不想使用的spring-boot组件,也许问题就在这里。我的安全配置在这里:@Configuration@Order(2147483636)publicclassSecurityConfigurationextendsWebSecurityConfigurerAdapter{@Overrideprotectedvoidconfigure

spring - 单例和原型(prototype) bean 有什么区别?

我是Spring的新手,我读到了这个:BasicallyabeanhasscopeswhichdefinestheirexistenceontheapplicationSingleton:meanssinglebeandefinitiontoasingleobjectinstanceperSpringIOCcontainer.Prototype:meansasinglebeandefinitiontoanynumberofobjectinstances.那么什么是“对象实例”。 最佳答案 原型(prototype)范围=每次注入(i