注入不起作用 - 外部JAR中的@component类
这是我在Spring应用程序中的测试课。
class MyTest{
@Inject
private Configuration config;
@Inject
VUtils vUtils;
@Test
method1(){
....
VUtilsP.method("test_property"); // VUtilsP is NULL here..
}
}
下面的类位于JAR中(添加为Maven依赖性到上述)
@Component
Class VUtilsP{
@Inject
Configuration configD;
public void method(String s){
// do something
configD.getConfig(s);
}
}
应用程序目录:
MyService
!- **src/test/java/MyTest.java**
!- External libraries
!- test-engine.jar
!- **src/java/VUtilsP.java**
我想将配置对象注入Vutilsp类,以便我可以在Vutilsp类中访问它。
我的方法是将Vutilsp转换为Bean并注入mytest,但这不起作用。 vutilsp为无效。请让我知道我在这里缺少什么,或提出一种使它起作用的不同方法。太感谢了。
This is my Test class inside spring application.
class MyTest{
@Inject
private Configuration config;
@Inject
VUtils vUtils;
@Test
method1(){
....
VUtilsP.method("test_property"); // VUtilsP is NULL here..
}
}
This below class is in jar (added as maven dependency to above)
@Component
Class VUtilsP{
@Inject
Configuration configD;
public void method(String s){
// do something
configD.getConfig(s);
}
}
application directory :
MyService
!- **src/test/java/MyTest.java**
!- External libraries
!- test-engine.jar
!- **src/java/VUtilsP.java**
I want to inject Configuration object to VUtilsP class so I can access it inside VUtilsP class.
My approach is to convert VUtilsP to a bean and inject into MyTest but this is not working. VUtilsP is null. Please let me know what I'm missing here or suggest a different approach to get it work. Thank you so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论