简体   繁体   English

构造函数参数的自定义bean解析器

[英]Custom bean resolver for constructor parameter

Is it possible to provide a custom bean resolver to spring? 是否可以提供自定义的bean解析器来启动? I have a constructor 我有一个构造函数

Person(@myCustomAnnotation name : String)

I want to be able to put a different value for name based on if the annotation is there or not. 我希望能够根据注释是否存在为名称输入不同的值。

I think the @Value annotation is what you're looking for. 我认为@Value注释是您要寻找的。 Person will have to be a managed bean though. 人将必须是一个托管bean。

@Bean("jim")
fun getJim(@Value("\${person.name:Jim Jones}") name : String) = Person(name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Security PreAuthorize自定义方法Bean解析器未注册? - Spring Security PreAuthorize Custom Method Bean resolver is not registered? 将参数传递给Spring中构造函数中引用的Bean - Passing a parameter to a bean referenced in a constructor in Spring 构造函数的参数 0 需要一个类型为“FileStoragePropertiesAedImages”的 bean - Parameter 0 of constructor required a bean of type 'FileStoragePropertiesAedImages' "" 中构造函数的参数 0 需要一个无法找到的类型为 "" 的 bean - Parameter 0 of constructor in "" required a bean of type "" that could not be found 构造函数的参数 0 需要一个找不到的 bean - Parameter 0 of constructor required a bean that could not be found Service 中构造函数的参数 0 需要一个 Repository 类型的 bean - Parameter 0 of constructor in Service required a bean of Repository type [] 中构造函数的参数 0 需要找不到类型 [] 的 bean - Parameter 0 of constructor in [] required a bean of type [] that could not be found 没有注册bean解析器 - Getting No bean resolver registered Spring 5 中带有请求参数bean的自定义参数名称 - Custom parameter names with a bean for request parameters in Spring 5 如何在Spring中实例化Class / Bean并在构造函数中传递参数 - How to instantiate a Class/Bean in Spring passing parameter in constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM