To configure a Spring bean, we'll create an application file named SSBasicAuthApplication.kt and use Java configuration, which configures Spring Security without writing any XML code.
Here's a simple code for the application file (SSBasicAuthApplication.kt):
@ComponentScan(basePackages = ["com.packtpub.sunnat629.ssbasicauth"])
@SpringBootApplication
class SSBasicAuthApplication: SpringBootServletInitializer()
fun main(args: Array<String>) {
runApplication<SSBasicAuthApplication>(*args)
}
Here, we've extended SpringBootServletInitializer. This runs SpringApplication from a traditional WAR archive. This class is responsible for binding the Servlet, Filter, and ServletContextInitializer beans from the application context to the server.
@SpringBootApplication is a convenience annotation that's equivalent to declaring @Configuration and @EnableAutoConfiguration for this SSBasicAuthApplication class.
Mention a package name or a collection of package names in the @ComponentScan annotation to specify the base packages. This is used with the @Configuration annotation to tell Spring packages to scan for annotated components.