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

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.

Related

How to register ApplicationContextInitializer in Spring boot 2.7/3

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.

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 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.

Spring 3.2 and #WebFilter annontation..is it supported?

I can't seem to find anything that talks about using the #WebFilter annotation, and having Spring 3.2 AbstractAnnotationConfigDispatcherServletInitializer correctly handle the params used.
Does Spring 3.2 support that annotation?
EDIT: based upon nicohlas answer
If I use the #WebFilter annontation, and set params inside of that...it looks like AbstractAnnotationConfigDispatcherServletInitializer registerServletFilter does not look at those annontations and setup things properly from those params: e.g url-mappings
Knowing that Spring 3.2 supports Servlet 3.0, shouldn't it support #WebFilter?
or am i missing the whole point of the WebFilter annontation?
EDIT 2:
When I deploy my war, and have #WebFilters defined inside that war, the container looks to "register" those...but, for some reason, even with the proper urlPatterns set, when the request comes into the DispatchServlet...it's like the filter doesn't get called.
#WebFilter is a JEE6 component, and is new to Servlet 3.0.
It is not something that Spring would support, but rather your application container (Tomcat, WebSphere, Glassfish, JBoss,...)
The idea here is to move configuration of your application container to Java, rather than utilizing the web.xml deployment descriptor.
EDIT:
It would seem to me that using the #WebFilter annotation would be for discovering Filter's via classpath scanning. The AbstractAnnotationConfigDispatcherServletInitializer#registerServletFilter method that you are asking about is taking in a Filter and does not look at the annotations on it.

create beans with annotation spring

In struts2 i almost did not use any xml configs and used much of annotations for MVC. I build a small application in that way using struts2. Now i want to develop same project using spring 3.2. Now i want to use annotation to create beans and request mapping (this i used). I want a clear example of using bean annotations and is it possible to set properties using annotations. I am getting confused because the documentation is too large, and many annotations. providing a simple list of annotations and their usage with simple example will be a great help.
Iam doing sample project on Spring 3.1.
I have used some annotations to create beans.Below are the annotations i have used.
#Component - Annotation used to create a bean given by Spring
#Resource,#Bean
JSR Annotations: #Controller,#Repository, #Service
If you are annotating your class with above annotations Spring Container will create beans for you.
Your properties will be set with help of #Autowired annotation.

Resources