我已经使用spring boot-spring数据启动程序jpa来读取AWS Lambda中的mysql内容。
,当我上传lambda并对其进行测试时-它运行正常。但是过了一会儿-大约30分钟后,我一次又一次收到此错误
org.springframework.context.annotation.AnnotationConfigApplicationContext@3ffc5af1 has been closed already
主处理程序类-由于没有主方法
@Component
@SpringBootApplication
public class LambdaRDSFunction implements RequestHandler<ApiGatewayProxyRequest, ApiGatewayProxyResponse> {
private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
public static AnnotationConfigApplicationContext ctx;
public static Thread shutDownHookThread = null;
static {
ctx = new AnnotationConfigApplicationContext(RDSReadConfiguration.class);
if (ctx == null)
ctx = new AnnotationConfigApplicationContext(RDSReadConfiguration.class);
else if (!ctx.isActive())
ctx.start();
//
// if (shutDownHookThread == null) {
// ctx.registerShutdownHook();
// shutDownHookThread = new Thread(() -> {
// ctx.close();
// });
// getRuntime().addShutdownHook(shutDownHookThread);
// }
}
private LambdaLogger logger;
public ApiGatewayProxyResponse handleRequest(ApiGatewayProxyRequest apiGatewayProxyRequest, Context context) {
logger = context.getLogger();
Gradle构建文件
apply plugin: 'java-library'
apply plugin: 'eclipse'
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.4.RELEASE'
runtime group:'mysql',name:'mysql-connector-java', version: '8.0.11'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.3'
compile group: 'com.amazonaws', name: 'aws-lambda-java-core', version: '1.1.0'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.4.RELEASE'
testCompile group: 'org.springframework', name: 'spring-test', version: '5.0.8.RELEASE'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.21.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jar {
manifest {
attributes "Main-Class": "com.baeldung.fatjar.Application"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task copyNativeDeps(type: Copy) {
from(configurations.compile + configurations.testCompile) {
include '*.dll'
include '*.dylib'
include '*.so'
}
into 'build/libs'
}
test {
dependsOn copyNativeDeps
systemProperty "java.library.path", 'build/libs'
}
task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtime
}
}
task depsize {
doLast {
final formatStr = "%,10.2f"
final conf = configurations.default
final size = conf.collect { it.length() / (1024 * 1024) }.sum()
final out = new StringBuffer()
out << 'Total dependencies size:'.padRight(45)
out << "${String.format(formatStr, size)} Mb\n\n"
conf.sort { -it.length() }
.each {
out << "${it.name}".padRight(45)
out << "${String.format(formatStr, (it.length() / 1024))} kb\n"
}
println(out)
}
}
build.dependsOn buildZip