尝试从外部 jar 访问接口时出现空指针
我在 gradle 上运行的 springboot 项目中包含了一个外部 jar,并且我试图从该 jar 的接口调用一个方法。我尝试自动装配它,但它只是抛出 BeanInstantiationException 并且我无法创建对象,因为它是一个接口并且不允许我创建。我尝试使用下面的代码创建一个 Bean,但仍然抛出 Bean 实例化异常。我尝试使用在 jar 内实现此接口的类,但它仍然抛出 bean 实例化异常。我尝试在我的主类中进行组件扫描来扫描这个 jar 包,但这不会让我在邮递员中运行该服务,它会抛出 404。不知道我还能尝试什么。
@Bean public HandlerImplementation HandlerImplementationService(){
return new HandlerImplementation();
}
I have included an external jar in my springboot project running on gradle and I'm trying to call a method from an interface from that jar. I tried to autowire it and it just throws BeanInstantiationException and I just can't create an object because it is an interface and won't let me. I tried to create a bean with the below code and still throws a Bean instantiation exception. I tried to use the class that is implementing this interface inside the jar and it still throws a bean instantiation exception. I tried to the component scan in my main class to scan this package of the jar but that will not let me run the service in postman, it throws a 404. Not sure what else I could try.
@Bean public HandlerImplementation HandlerImplementationService(){
return new HandlerImplementation();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请确保您将外部 jar 添加为 Gradle 中的依赖项。
Please make sure you added the external jar as a dependency in your Gradle.