Monday 15 August 2011

How to autowire @service from external Jar in Spring -



How to autowire @service from external Jar in Spring -

i developing 2 spring based application(ex app1 , app2) on java configuration maven , no xml config. through maven -war plugin , have created jar reference of app2 , using mvn install:install file have binded app2 jar app1. app2 - used fetch inforamtion info source.

i have autowired app2 serive in app1 implementation class fetch details annotated @service in app2 application.

my first uncertainty is:

both app1 , app2 have separate appconfig.java file.is possible autowiring 1 of @service availble in jar format or else need define or import app2's appconfig java file app1's appconfig.jave file.

i have tried simple autowired external jar @service class , ended error.

kindly help me on needs done autowire external jar's @service implementation class.

below 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... } grab (exception ex) { // handle exception here } { } homecoming vehicledetails; } }

vehicleservice 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(); homecoming vehicle; }

let's create simple. app1 depends on app2. utilize @import(app2config.class) class app1config {}, that's it.

and way, instead of tricks 'mvn install:install file' can utilize parent pom.xml modules app1 , app2, , declare dependency of module app1 on module app2 in pom.xml <dependencies> section. run 'mvn install' build project. see illustration here: http://books.sonatype.com/mvnex-book/reference/multimodule.html

spring service jar autowired maven-war-plugin

No comments:

Post a Comment