考虑以下(检票口)代码:
@SpringBean(required=false)
private StatusCheckService service;
在我的用例中,我的上下文中没有 StatusCheckService 类型的 bean。这不是问题,它被标记为可选,因此(检票口)页面将初始化得很好。
然而:
@SpringBean(name = "statusCheckService", required=false)
private StatusCheckService service;
这失败了:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'statusCheckService' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:400)
at org.springframework.context.support.AbstractApplicationContext.isSingleton(AbstractApplicationContext.java:1113)
at org.apache.wicket.spring.SpringBeanLocator.isSingletonBean(SpringBeanLocator.java:100)
at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:140)
我希望这没有什么区别。好的,没有具有这样名称的 bean,但我将其标记为可选,为什么会出现异常?有没有办法解决?