diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/pom.xml index 59374bdbe..65efa8a49 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/pom.xml +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/pom.xml @@ -15,7 +15,6 @@ UTF-8 UTF-8 - 1.8 @@ -30,7 +29,6 @@ jakarta.servlet jakarta.servlet-api - provided org.springframework diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/pom.xml index 5654a15e7..1121bde52 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/pom.xml +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/pom.xml @@ -32,48 +32,17 @@ + + io.github.crac + org-crac + 0.1.3 + org.springframework.cloud spring-cloud-function-adapter-aws-web - 3.2.9-SNAPSHOT + 4.0.3-SNAPSHOT - - - org.springframework - spring-context-indexer - ${spring.version} - true - - - - org.apache.logging.log4j - log4j-core - ${log4j.version} - - - - org.apache.logging.log4j - log4j-api - ${log4j.version} - - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} - - - - com.amazonaws - aws-lambda-java-log4j2 - 1.5.1 - - + junit junit diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/src/main/java/oz/spring/petstore/PetStoreSpringAppConfig.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/src/main/java/oz/spring/petstore/PetStoreSpringAppConfig.java index 3969ea641..c3c8dca64 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/src/main/java/oz/spring/petstore/PetStoreSpringAppConfig.java +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/src/main/java/oz/spring/petstore/PetStoreSpringAppConfig.java @@ -16,9 +16,6 @@ package oz.spring.petstore; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -29,25 +26,13 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + @Configuration @Import({ PetsController.class }) public class PetStoreSpringAppConfig { - /* - * Create required HandlerMapping, to avoid several default HandlerMapping instances being created - */ - @Bean - public HandlerMapping handlerMapping() { - return new RequestMappingHandlerMapping(); - } - - /* - * Create required HandlerAdapter, to avoid several default HandlerAdapter instances being created - */ - @Bean - public HandlerAdapter handlerAdapter() { - return new RequestMappingHandlerAdapter(); - } /* * optimization - avoids creating default exception resolvers; not required as the serverless container handles diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/template.yml b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/template.yml index 0bf39c644..75d452776 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/template.yml +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store/template.yml @@ -11,10 +11,14 @@ Resources: PetStoreFunction: Type: AWS::Serverless::Function Properties: +# AutoPublishAlias: bcn + FunctionName: pet-store-17 Handler: org.springframework.cloud.function.adapter.aws.web.WebProxyInvoker::handleRequest Runtime: java17 + SnapStart: + ApplyOn: PublishedVersions CodeUri: . - MemorySize: 512 + MemorySize: 1024 Policies: AWSLambdaBasicExecutionRole Timeout: 30 Environment: @@ -32,6 +36,6 @@ Outputs: Description: URL for application Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/pets' Export: - Name: PetStoreLambda + Name: SpringPetStoreApi diff --git a/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ProxyMvc.java b/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ProxyMvc.java index da07ab890..3762f0dcf 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ProxyMvc.java +++ b/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ProxyMvc.java @@ -72,8 +72,6 @@ public class ProxyMvc { private ServletContext servletContext; - private volatile boolean initialized; - public ConfigurableWebApplicationContext getApplicationContext() { return this.applicationContext; } @@ -83,15 +81,7 @@ public class ProxyMvc { } public static ProxyMvc INSTANCE(ConfigurableWebApplicationContext applpicationContext) { - ProxyServletContext servletContext = new ProxyServletContext(); - applpicationContext.setServletContext(servletContext); - DispatcherServlet dispatcher = new DispatcherServlet(applpicationContext); - ServletRegistration.Dynamic reg = servletContext.addServlet("dispatcherServlet", dispatcher); - reg.setLoadOnStartup(1); - - ProxyMvc mvc = new ProxyMvc(dispatcher, applpicationContext); - mvc.servletContext = servletContext; - return mvc; + return new ProxyMvc(applpicationContext); } public static ProxyMvc INSTANCE(Class... componentClasses) { @@ -103,12 +93,26 @@ public class ProxyMvc { return INSTANCE(applpicationContext); } + /** * Private constructor, not for direct instantiation. */ - ProxyMvc(DispatcherServlet dispatcher, ConfigurableWebApplicationContext applicationContext) { + ProxyMvc(ConfigurableWebApplicationContext applicationContext) { this.applicationContext = applicationContext; - this.dispatcher = dispatcher; + ProxyServletContext servletContext = new ProxyServletContext(); + this.applicationContext.setServletContext(servletContext); + this.dispatcher = new DispatcherServlet(this.applicationContext); + this.dispatcher.setDetectAllHandlerMappings(false); + + ServletRegistration.Dynamic reg = servletContext.addServlet("dispatcherServlet", dispatcher); + reg.setLoadOnStartup(1); + this.servletContext = applicationContext.getServletContext(); + try { + this.dispatcher.init(new ProxyServletConfig(this.servletContext)); + } + catch (Exception e) { + throw new IllegalStateException(e); + } } public void stop() { @@ -131,13 +135,6 @@ public class ProxyMvc { } public void service(HttpServletRequest request, HttpServletResponse response, CountDownLatch latch) throws Exception { - synchronized (this) { - if (!this.initialized) { - this.dispatcher.init(new ProxyServletConfig(this.servletContext)); - this.initialized = true; - } - } - ProxyFilterChain filterChain = new ProxyFilterChain(this.dispatcher); filterChain.doFilter(request, response);