java - 通过 GenericApplicationContext 注册 SpringBoot bean 不起作用
问题描述
我在运行时这里有一个简单的 bean 注册,但它不起作用:
@GetMapping("/hi")
public void hi()
{
MyClass myClass = new MyClass();
genericApplicationContext.registerBean("mybean", MyClass.class, myClass);
}
@GetMapping("/bye")
public Integer bye()
{
MyClass myClass = (MyClass) genericApplicationContext.getBean("mybean");
return myClass.hi;
}
调用方法hi()
一切正常,但是当我调用bye()
方法时,我得到了这个异常:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybean': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)] with root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybean': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
这里发生了什么?
解决方案
推荐阅读
- python - Pandas 中基于多个列表和空格替换的列总和
- html - 如何使数据表固定高度和固定分页
- java - 如何从 csv 文件读取数据,将其存储到内存,然后将内存写回 csv 文件(同时删除读取的最后一行)?
- flutter - Flutter Int_phone_field 如何将文本字段与国家代码选择器对齐
- stack - 尝试编译时遇到继承问题
- xcode - 架构 x86_64 的未定义符号 - XCode 模拟器
- c - 如何删除结构中的值?
- php - 将标题表单从输入文本更改为多选菜单
- flutter - 快照数据为空,但响应即将到来
- javascript - 如何捕捉消息中表情符号的反应