I am developing two spring based application(Ex app1 and app2) fully on Java configuration with Maven and no XML config.
Through Maven -WAR plugin , I have created Jar reference of app2 and using mvn install:install file
I have binded the app2 jar with app1.
app2 - Its used to fetch inforamtion from data source.
I have autowired the app2 serive in app1 implementation class to fetch the details which was annotated with @Service
in app2 application.
My first doubt is:
Both app1 and app2 have separate AppConfig.java file.Is it possible to simply autowiring one of the @Service
which is availble in Jar format or else I need to define or import App2's AppConfig java file into App1's AppConfig.jave file.
I have tried with the simple autowired the external JAR @Service
class and ended with error.
Kindly help me on what needs to be done to autowire external Jar's @Service
to the
implementation class.
Below is my App1 repository class
@Repository
public class VehicleRepository {
@Autowired
VehicleService vehicleservice;
public Map<String, item> getAllTypes(String type) {
Vehicke vehicle = vehicleservice.getAllVehicle(type);
// handle response here...
} catch (Exception ex) {
// handle exception here
} finally {
}
return vehicleDetails;
}
}
VehicleService
is available in external Jar.
VehicleService Class:
@Service
public class VehicleService {
public VehicleService() {
}
@Autowired
PortRepository portRepository;
@Autowired
MessageSource messageSource;
public Vehicle getAllVehicles(String type) {
List<Vehicle> cehicles = portRepository.getPorts();
return vehicle;
}