Sunday, September 5, 2021

SpringBoot: Configuration Classes & Running Application

 

@Configuration

·         Spring recommends primary source of configuration as a single class with @Configuration (i.e. Java configuration over XML configuration)


·         If you have additional configuration classes, use @Import annotation to import those in @Configuration class


·         XML configuration can also be imported in Java using @ImportResource annotation to load XML configuration files


@SpringBootConfiguration

·         An alternative to Springs @Configuration that enables registration of extra beans in the context

·         Import additional configuration classes

·         Configuration detection in your integration test i.e. Spring Test Framework


@EnableAutoConfiguration

·         Should be added to @Configuration class


·         A class can be excluded from Auto-configuration using attributes, exclude (if class is on classpath) or excludeName (fully qualified name, if not on classpath)


@ComponentScan

·         Spring recommends constructor injection and scanning components using @ComponentScan


·         @ComponentScan detects @Component, @Service, @Repository, @Controller, etc. and automatically registers it as Spring Bean


@SpringBootApplication

·         This single annotation includes 3 annotations mentioned above @SpringBootConfiguration, @EnableAutoConfiguration and @ComponentScan


Running Application

·         java -jar target/myapplication-0.0.1-SNAPSHOT.jar

·         It is also possible to run packaged application in debugging mode, doing so lets you attach debugger to your packaged application

·         java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \ -jar target/myapplication-0.0.1-SNAPSHOT.jar

Using Maven plugin “mvn spring-boot:run” run compiles and runs the app

No comments:

SpringBoot: Features: SpringApplication

Below are a few SpringBoot features corresponding to SpringApplication StartUp Logging ·          To add additional logging during startup...