spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 355 forks source link

Custom @ComponentScan not running/loading spring beans in dependency package when executing as an AWS Lambda Function #1657

Closed jglesner closed 2 years ago

jglesner commented 2 years ago

I have a project that uses spring-cloud-function-adapter-aws. My main class has a custom @ComponentScan that forces a scan of a package dependency I bring in with maven.

@SpringBootApplication
@ComponentScan(basePackages = {"com.mypackage.mobileapi", "com.mypackage.data"})
public class MobileapiApplication {
    public static void main(String[] args) {
        SpringApplication.run(MobileapiApplication.class, args);
    }
}

In the com.mypackage.data dependency, I set up HikariCP in an @Configuration class that uses an @Profile annotation. I have that profile set to active in my application.properties file. When testing locally, everything works as expected. The com.mypackage.data configuration class is loaded and the Hikari dataSource is created.

However, when uploading and testing my MobileapiApplication in AWS Lambda, the component scan is not running. As a result, my Hikari dataSource isn't getting created and my function complains that I have not setup a dataSource. I am not using spring.cloud.function.scan.packages in my application.properties file, so the @ComponentScan shouldn't be getting overridden.

Why would running this package as an AWS Lambda prevent the custom @ComponentScan?

I'm using spring-boot-starter-parent 2.7.1 with dependencyManagement of spring-cloud-dependencies 2021.0.3.

jglesner commented 2 years ago

Meant to post this to spring-cloud/spring-cloud-function repo.