[ad_1]
I’m trying to test a lambda function (spring boot cloud app), but getting java.lang.ClassNotFoundException
eventhough the stream handler is properly mentioned under runtime
settings.
Error Message:
{
"errorMessage": "Class not found: com.myexample.handler.ServiceHandler",
"errorType": "java.lang.ClassNotFoundException"
}
Here is the stream handler code:
package com.myexample.handler;
@Slf4j
@Component
public class ServiceHandler implements RequestHandler<String,Object> {
@Autowired
MyService myService ;
@Override
public Object handleRequest(String s, Context context) {
// myService.executeMethod();
}
I’m using maven shade plugin to build the jar with all dependencies:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>aws</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Other important maven dependencies added (apart from regular spring boot dependencies
) in my project for this purpose:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-aws</artifactId>
<version>3.2.5</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.11.0</version>
</dependency>
Few things to note here is: I’m using @Component
annotation in the ServiceHandler
class. I had to do this, because I need to autowire the service.
I have no clue what’s going wrong here as I don’t see anything wrong at lambda side as well as the code. Any suggestions would be really appreciated. Thanks!
[ad_2]