How to register ApplicationContextInitializer in Spring boot 2.7/3 - spring-boot

I'm using Spring boot 2.7.7 and Spring boot 3.
I've already switched to the new way write my custom autoconfiguration class - that is with #AutoConfiguration and org.springframework.boot.autoconfigure.AutoConfiguration.imports inside META-INF/spring folder.
I want to add ApplicationContextInitializer. How do I do it the last spring boot versions (2.7.7 and 3)? I tried to add it to org.springframework.boot.autoconfigure.AutoConfiguration.imports file but initialize method is not being called.

Related

How to reproduce Spring Boot Configuration POJO creation but in Spring Core (No boot)

The Context
As described in the Spring Boot documentation, one of the ways to create a POJO that holds configuration properties values is:
//On the configuration class
#EnableConfigurationProperties(value = {
POJO_CLASS_HERE.class
})
//On the POJO Class
#ConfigurationProperties(prefix = "PROPERTIES_PREFIX_HERE")
#ConstructorBinding
It works fine - when you have Spring boot in the project.
Now, I have another project that has only Spring V4 (core + batch) - No boot.
The Question
How to use/reproduce the Configuration POJO creation of Spring Boot in Spring core ?
Spring Boot - Type Safe Configuration properties

Is there any bean created for spring #propertySource annotation

I have used spring #propertysource annotation to load properties file in my spring boot project . I just need to know is there any bean created for this annotation when application gets started
#PropertySource annotation is used to let spring-boot know the location of the properties required by your application. It will not create any bean.

Is it possible to use Spring boot with web.xml and annotation based configurataion

I want to use Spring Boot with web.xml and servlet 3.1 configuration.Is there any example?
I want to define my context(Dispatcher servlet/SpringBootServletInitializer) in Web.xml mean time define all other configuration using annotation based.Ex want to load application.properties/yml values using pojos.
Need this type of configuration to deploy the app in Liberty profile as Liberty expecting application context in web.xml when using liberety global sharelib.

How to add Struts2 to a web application without web.xml?

Can someone help me with a minimal project setup with Spring Boot and Struts2?
I have already create a Spring Boot application with a H2-database. I also added a h2Configuration class, so that I'm able to access the database with localhost:8080/console.
But how can I add Struts2 to my Application without web.xml?
Without web.xml you can only write a Struts2 filter using servlet 3.0 or higher
#WebFilter("/*")
public class Struts2Filter extends Struts2PrepareAndExecuteFilter {
}
The content could be empty, it's enough to add annotated filter without any inclusion in the web.xml file.
If you want to integrate Struts2 with Spring, then you should use a plugin.
Struts 2 provides a plugin that enables Spring to inject into the ActionSupport classes any dependent objects you've specified in the Spring configuration file. Consult Spring Plugin documentation for more information about how the plugin works.

How to disable Spring Boot's autoconfiguration for Apache Velocity?

I'm experimenting with Spring Boot (1.1.9.RELEASE) and Apache Velocity (1.7) with the intention of using Velocity as a templating tool for generating emails. I'm using Thymeleaf (2.1.3.RELEASE) for web templates.
Spring Boot's Autoconfiguration detects Velocity on the classpath during start up and adds it as a web view resolver. While this is brilliant, it's not what I want so I tried
#EnableAutoConfiguration(exclude = {VelocityAutoConfiguration.class})
public class Application {
but I still ended up with a velocityViewResolver bean once the application had started up.
Any idea how I might go about disabling this automatic configuration?
Thanks in advance for any replies.
With Spring Boot 1.2.5, disabling the autoconfiguration on the main application class seems to be enough:
#SpringBootApplication
#EnableAutoConfiguration(exclude = { VelocityAutoConfiguration.class })
Edit
I don't exactly know since when that works, but now (Spring Boot 1.3.2) you can also set :
spring.velocity.enabled=false
in application.properties.

Resources