如何从静态内部类构造函数创建 Spring bean?
我正在尝试使用 Spring Framework IoC 容器来创建类的实例 ThreadPoolExecutor.CallerRunsPolicy。在 Java 中,我会这样做......
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
...
RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
但是当我尝试在 Spring 中执行相同的操作时,它会抛出 CannotLoadBeanClassException。
<beans>
<bean class="java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy"/>
</beans>
更一般地说:在 Spring ApplicationContext XML 中,如何调用静态内部类的构造函数?
I am trying to use the Spring Framework IoC Container to create an instance of class
ThreadPoolExecutor.CallerRunsPolicy. In Java, I'd do it this way...
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
...
RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
But when I try to do the equivalent in Spring, it throws a CannotLoadBeanClassException.
<beans>
<bean class="java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy"/>
</beans>
More generally: in a Spring ApplicationContext XML, how can you call a constructor of a static inner class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为它不起作用的原因是 Spring 无法将其理解为静态内部类。
也许这可以工作:
I think the reason it is not working is because Spring is not able to understand it as a static inner class.
Probably this can work:
使用
工厂方法
属性:Use the
factory-method
attribute: