Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是春天的新手。我们如何将对象传递给应用程序上下文 xml 文件?
例如:
我有类A调用:
A
`new ClassPathXmlApplicationContext("META-INF/spring/storage.xml");
storage.xml在其中定义了一个 bean(属于 class B)。
storage.xml
B
我想从创建类对象B并A通过ApplicationContext.
ApplicationContext
我该怎么做?
这是简单的方法。在 A 类
ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/storage.xml"); B objB = (B) context.getBean("beanIDofB"); objB.someMehodOfB();
但是这种做法已经过时了。试试spring注解