Can I programmatically determine if a spring bean

2019-06-18 14:57发布

When I get a spring bean (via getBean()), is there any way to verify from java code that the bean has been defined with scope=prototype ?

Spring config:

<bean class="foo.Bar" scope="prototype" />

Java:sc

MyBean bean = springApplicationContext.getBean("MyBean");

I could just instantiate it twice and compare the objects, but I'd like to avoid unnecessary object creation. Something like the opposite of this answer would do the trick: https://stackoverflow.com/a/9125610/156477

1条回答
做个烂人
2楼-- · 2019-06-18 15:21

You have a API boolean isPrototype(String name) in ApplicationContext to check it.

查看更多
登录 后发表回答