java - AWS lambda + spring boot = not wiring component -
i´m trying use spring-boot inside aws lambda application make calls soap web-service. looks isn´t autowiring soap component. here´s code:
@springbootapplication(scanbasepackages={"com.fenix"}) @enableautoconfiguration @componentscan public class aplicacao extends springbootservletinitializer { public static void main(string[] args) { springapplication.run(aplicacao.class, args); } @override protected springapplicationbuilder configure(springapplicationbuilder springapplicationbuilder) { return springapplicationbuilder.sources(aplicacao.class); } } @configuration public class beans { @bean public jaxb2marshaller marshaller() { jaxb2marshaller marshaller = new jaxb2marshaller(); marshaller.setpackagestoscan("com.tranzaxis.schemas", "org.radixware.schemas", "org.xmlsoap.schemas", "com.compassplus.schemas"); return marshaller; } @bean public tranclient tranclient(jaxb2marshaller marshaller) { tranclient client = new tranclient(); client.setdefaulturi("http://rhel72.tx:12301?wsdl"); client.setmarshaller(marshaller); client.setunmarshaller(marshaller); return client; } @bean(name = "tran") public tranclient gettranclient() { return tranclient(marshaller()); } } public class postmovimentacao extends handler implements service { @autowired @qualifier("tran") private tranclient tranclient; @inject private pessoacompassbo pessoacompassbo; private compassconfig compassconfig; private static final logger logger = logger.getlogger(postmovimentacao.class); @override protected responseentity execute(apirequest request, context context) throws httpexception { movimentacaorequest movimentacaorequest = new movimentacaorequest(); movimentacaorequest.setorigem(669l); movimentacaorequest.setdestino(657l); movimentacaorequest.setvalor(bigdecimal.valueof(1l)); traninvoke invoke = tranclient.movimentacaofinanceira(movimentacaorequest, compassconfig); -->nullpointer here return responseentity.of(optional.of(invoke), optional.empty(), httpstatus.sc_ok); } @override public void setup() { try { compassconfig = compassconfig.build(); } catch (invalidconfigexception e) { logger.error("compass config error", e); } } }
here´s pom.xml:
<build> <finalname>integrador-compass</finalname> <pluginmanagement> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <version>1.5.6.release</version> <configuration> <layout>module</layout> </configuration> </plugin> </plugins> </pluginmanagement> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.6.0</version> <configuration> <source>${maven.compiler.source}</source> <target>${maven.compiler.target}</target> <encoding>${project.build.sourceencoding}</encoding> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-shade-plugin</artifactid> <version>2.3</version> <configuration> <createdependencyreducedpom>false</createdependencyreducedpom> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> <plugin> <groupid>org.pitest</groupid> <artifactid>pitest-maven</artifactid> <version>1.1.11</version> <configuration> <targetclasses> <param>com.fenix.*</param> </targetclasses> <excludedclasses> <excludedclasse>com.fenix.handler.request*</excludedclasse> <excludedclasse>com.fenix.handler.response*</excludedclasse> <excludedclasse>com.fenix.model*</excludedclasse> </excludedclasses> <avoidcallsto> <avoidcallsto>java.util.logging</avoidcallsto> <avoidcallsto>org.apache.log4j</avoidcallsto> <avoidcallsto>org.slf4j</avoidcallsto> <avoidcallsto>org.apache.commons.logging</avoidcallsto> </avoidcallsto> <timestampedreports>false</timestampedreports> <outputformats> <outputformat>xml</outputformat> <outputformat>html</outputformat> </outputformats> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-surefire-plugin</artifactid> <version>2.16</version> <configuration> <includes> <include>**/*tests.java</include> <include>**/*test.java</include> </includes> </configuration> </plugin> </plugins> <extensions> <extension> <groupid>org.springframework.build</groupid> <artifactid>aws-maven</artifactid> <version>5.0.0.release</version> </extension> </extensions> </build> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.3.0.release</version> </parent> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-security</artifactid> <exclusions> <exclusion> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-logging</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupid>org.springframework.ws</groupid> <artifactid>spring-ws-core</artifactid> </dependency> <dependency> <groupid>com.fenix</groupid> <artifactid>compass-api</artifactid> <version>0.0.15</version> </dependency> <dependency> <groupid>com.fenix</groupid> <artifactid>lambda-commons</artifactid> <version>1.6.2</version> </dependency> <dependency> <groupid>commons-validator</groupid> <artifactid>commons-validator</artifactid> <version>1.5.1</version> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupid>org.mockito</groupid> <artifactid>mockito-core</artifactid> <version>2.6.2</version> <scope>test</scope> </dependency> <dependency> <groupid>org.assertj</groupid> <artifactid>assertj-core</artifactid> <version>3.6.2</version> <scope>test</scope> </dependency> <dependency> <groupid>com.mashape.unirest</groupid> <artifactid>unirest-java</artifactid> <version>1.4.9</version> </dependency> </dependencies>
has used configuration? added spring-boot cause way make soap calls. if try make call using code wsdl, when tries connect server, got error saying request empty. spring-boot doesn´t need connect first, sends request , works fine.
any welcome.
thanks lot.
apparently, spring boot application context not being initialized in code...if want use spring boot in lambda function try like:
pom.xml
<parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.4.0.release</version> </parent> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>com.amazonaws</groupid> <artifactid>aws-java-sdk-core</artifactid> <version>1.11.181</version> </dependency> <dependency> <groupid>com.amazonaws</groupid> <artifactid>aws-lambda-java-core</artifactid> <version>1.1.0</version> </dependency> <dependency> <groupid>com.amazonaws</groupid> <artifactid>aws-java-sdk-lambda</artifactid> <version>1.11.181</version> </dependency> </dependencies>
service example:
@component public class myservice { public void dosomething() { system.out.println("service doing something"); } }
some bean example:
@component public class mybean { @autowired private myservice service; public void executeservice() { service.dosomething(); } }
a lambda handler example:
@springbootapplication public class lambdahandler implements requesthandler<request, response> { private applicationcontext getapplicationcontext(string [] args) { return new springapplicationbuilder(lambdahandler.class) .web(false) .run(args); } public response handlerequest(request input, context context) { applicationcontext ctx = getapplicationcontext(new string[]{}); mybean bean = ctx.getbean(mybean.class); bean.executeservice(); return new response(); } }
wiki
Comments
Post a Comment