JVM内部回调参考: 注意: 我们创建了一个jar文件(即docService)。在那个jar中,我们将使用某种方法,并在将jar文件添加到其他springbootapp的项目构建路径中的任何位置处获取一些数据(即SalesService是微服务,它具有类似getSalesData的方法,并将数据提供给jar文件docService,文档创建)。
When we trying to get some data from the running spring boot app(i.e SalesService) from the jar file (i.e docService). The dao of the running springbootapp (i.e SalesService) is not getting injected/autowired. it showing null. How we can resolve this issue?
Implementation method inside the jar (i.e docService):
public void getData(){
Long id = 123678l;
Class<?> newclass = null;
Object object = null;
Method method = null;
String value = null;
try {
newclass = Class.forName(businessObject);
object = newclass.newInstance();
method = object.getClass().getMethod(callbackAddress, Long.class);
value = (String) method.invoke(object, id); //trying to get data from the running spring boot app using relection (i.e getSalesData() method)
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("getSalesData value::::::::::::" + value);
}
Implementation method of running springbootapp (i.e SalesService):
@Autowired
private SalesDao salesDao;
@SuppressWarnings("javadoc")
@Override
public SalesEntity getSalesData(Long id) {
SalesEntity salesEntity = null;
try {
salesEntity = new SalesEntity();
salesEntity = salesDao.findOne(id);
} catch (Exception e) {
e.getMessage();
}
return salesEntity;
}
we have tried another one way. But in this way also we faced issue.
we have added the docService package in the running springbootapp (i.e SalesService)
@SpringBootApplication
@EntityScan(basePackages = { "com.spring.offeringservice" }, basePackageClasses = { AdvancedRevisionEntity.class })
@EnableGlobalMethodSecurity(jsr250Enabled = false)
@ComponentScan(basePackages = { "com.spring.docservice" })
public class SpringBootApp {
public static void main(String[] args) {
SpringApplication.run(SpringBootApp.class, args);
}
}
adding dependency in the pom file of running springbootapp (i.e SalesService)
<dependency>
<groupId>docService</groupId>
<artifactId>docService-lib</artifactId>
<version>1.00</version>
</dependency>
Can any one help us to resolve this issue?