草庐IT

Bean-IOC

全部标签

java - 使用 Spring IoC 设置枚举值

有没有办法在构建时通过SpringIoC设置此类枚举值?我想做的是在类加载时注入(inject)硬编码在下面代码片段中的值:publicenumCar{NANO("VeryCheap","India"),MERCEDES("Expensive","Germany"),FERRARI("VeryExpensive","Italy");publicfinalStringcost;publicfinalStringmadeIn;Car(Stringcost,StringmadeIn){this.cost=cost;this.madeIn=madeIn;}}假设该应用程序必须部署在Nanos“

java - 使用 Spring IoC 设置枚举值

有没有办法在构建时通过SpringIoC设置此类枚举值?我想做的是在类加载时注入(inject)硬编码在下面代码片段中的值:publicenumCar{NANO("VeryCheap","India"),MERCEDES("Expensive","Germany"),FERRARI("VeryExpensive","Italy");publicfinalStringcost;publicfinalStringmadeIn;Car(Stringcost,StringmadeIn){this.cost=cost;this.madeIn=madeIn;}}假设该应用程序必须部署在Nanos“

spring - 如何使用注释将 bean 指定为非惰性

有谁知道在使用注解配置bean时如何将bean指定为nonlazy? 最佳答案 在spring3.0中有一个注解:@Lazy(false).但请注意,bean默认是Eager。 关于spring-如何使用注释将bean指定为非惰性,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/1027129/

spring - 如何使用注释将 bean 指定为非惰性

有谁知道在使用注解配置bean时如何将bean指定为nonlazy? 最佳答案 在spring3.0中有一个注解:@Lazy(false).但请注意,bean默认是Eager。 关于spring-如何使用注释将bean指定为非惰性,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/1027129/

java - 单例中的 Spring Prototype 范围 bean

我正在尝试在singletonbean中注入(inject)prototypebean,这样每次对单例bean方法的新调用都有一个原型(prototype)bean的新实例。考虑如下的单例bean:@ComponentpublicclassSingletonBean{@AutowiredprivatePrototypeBeanprototypeBean;publicvoiddoSomething(){prototypeBean.setX(1);prototypeBean.display();}}我希望每次调用doSomething()方法时,都会使用一个新的PrototypeBean实

java - 单例中的 Spring Prototype 范围 bean

我正在尝试在singletonbean中注入(inject)prototypebean,这样每次对单例bean方法的新调用都有一个原型(prototype)bean的新实例。考虑如下的单例bean:@ComponentpublicclassSingletonBean{@AutowiredprivatePrototypeBeanprototypeBean;publicvoiddoSomething(){prototypeBean.setX(1);prototypeBean.display();}}我希望每次调用doSomething()方法时,都会使用一个新的PrototypeBean实

java - Spring mvc 发现不明确的映射。无法映射 Controller bean 方法

我正在尝试构建一个应用程序,该应用程序可以列出数据库中的一些值,并在必要时使用Spring4修改、添加、删除,我收到以下错误(仅当我的两个Controller文件,如果我从它可以工作的文件之一中删除注释,但我在控制台中收到一条消息“没有找到映射......在具有名称的调度程序servlet中......):INFO:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping-Mapped"{[/edit/{id}],methods=[],params=[],headers=[],c

java - Spring mvc 发现不明确的映射。无法映射 Controller bean 方法

我正在尝试构建一个应用程序,该应用程序可以列出数据库中的一些值,并在必要时使用Spring4修改、添加、删除,我收到以下错误(仅当我的两个Controller文件,如果我从它可以工作的文件之一中删除注释,但我在控制台中收到一条消息“没有找到映射......在具有名称的调度程序servlet中......):INFO:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping-Mapped"{[/edit/{id}],methods=[],params=[],headers=[],c

源码解析来看spring.main.allow-bean-definition-overriding=true配置nacos中不生效问题

报错信息springboot项目启动报错:ErrorstartingApplicationContext.Todisplaytheconditionsreportre-runyourapplicationwith‘debug’enabled.2022-03-2816:55:30.412ERROR10564—[main]o.s.b.d.LoggingFailureAnalysisReporter:APPLICATIONFAILEDTOSTARTDescription:Thebean‘redisTemplate’,definedinclasspathresource[com/uhu/redis/c

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

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