explication about difference in the web.xml of a Java EE projects using struts 2 spring 3 and hibernate - spring

I'm trying to integrate Struts 2 with Spring and Hibernate. There are things that I don't understand in the web.xml :
What's the difference between the Struts 2 "filter-class" tags which have the following values:
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter <br/>
or
org.apache.struts2.dispatcher.FilterDispatcher <br/><br/>
Why do we use a Filter for Struts and use a Listener for Spring, and shat is the difference between them.
Why in some projects we can omit the hibernate filter and in the others we use it.

Its like a lot of questions and here are answers to few of them.
Filter Dispatcher and StrutsPrepareAndExecuteFilter are there to perform same work and StrutsPrepareAndExecuteFilter is the latest version of FiterDispatcher with a lots of improvement and keep in mind the future needs. So in short FiterDispatcher is deprecated.
StrutsPrepareAndExecuteFilter is the entry point of S2 and is responsible for handling any request and response.In short Filter is used for monitoring request and response from client to the servlet, or to modify the request and response, or to audit and log.
Listener is used for listening to events in a web containers, such as when you create a session, or place an attribute in an session.
So this gives a brief idea about whey we are using Filters for S2 and Listeners for Spring and you can do more googling to get more information about there differences and how hey work.
Hibernate filters are used in some specific use-cases.one such use case is to filtering the results of searches. Sometimes it is required to only process a subset of the data in the underlying Database tables and there can be many more such use case for hibernate filters and they only come in to play if you need them.

Related

Spring Boot 3 does not populate open telemetry field `http.route` where Spring Boot 2 did

Updating from Spring Boot 2 to 3 has changed the data and fields that are sent to my observability tooling, in a way that makes it less clear and harder to use.
On Spring Boot 2 I'd get spans and traces sent out that populated http.route with the URL plus a generic for any path parameters.
This is really useful, because I can filter on http.path and see all requests for a particular resource. The http.target is also populated with the specific actual request, not the templated one seen in http.route - so I get both the specific information in target if I want it as well as the generic info in route.
Moving to Spring Boot 3 I noticed that http.route is no longer populated, instead of e.g. /resource/{identifier} I can see that http.route is now just populated with /* - which isn't as useful for filtering.
I can't filter on a particular route anymore, I can only filter by the target, which means each resource with each unique identifier appears as a result. I've lost the generic ability to analyse and now can only look at specific instances of paths.
This means, for example, I've lost the ability to count the occurrences of a particular route. I can't test for request duration or anything else on a route. I can only test for these things on specific resources.
I have a few questions here:
Is this a bug? Should http.route still be populated? In which case where should that be logged? With the Spring Boot project? With an open telemetry dependency they rely on?
If it's not a bug, how can I restore the ability I had to query my data when http.route was populated? What other fields should I be using?
The root cause (if this is a bug) could be hidden in many places, across many organisations - I wonder if it's worth (particularly while open telemetry is growing in adoption rapidly) a flow chart of all the places where things could break, and mapping those items to orgs? (Off the top of my head, it could be a bug raised on the spring boot project, the spring project, the open telemetry java distribution project or potentially with my observability tooling provider).

What's the bare minimum topics to cover from JSP and Servlet to learn SpringBoot?

So I Want to build projects using spring Boot directly as I'm under a bit of time crunch. Please help me out.
What you need to know about JSP: nothing. JSP is old and clunky, use Thymeleaf instead. But if you're building single page web apps you don't need any templates, you just need to know how to accept and return JSON.
Servlets: you need to understand the threading model, that there's only one servlet being traversed by multiple threads, and any instance variables will be accessed by all the http request threads. More than servlets you need to know filters, because Spring Security uses them.

Spring : Auto Generate CRUD Rest Controller

Is there a way to generate spring rest crontroller for a business flow.
I want to generate CRUD services for given database object.For example, "employee_mst" , generate CRUD services code automatically.This is similar to what we used to have in hibernate or what we have in loopback.io for node. Appreciate any help around it.
I found a link that may answer your question: https://docs.spring.io/spring-data/rest/docs/current/reference/html/.
This text explains that Spring Data REST generates REST interfaces from Spring Data repositories.
I intend to try this but did not do so yet.
EDIT: I saw in my example application that Spring Data REST did what I expected. I could request all entities in my Spring Data repository using a HTTP request. The returned JSON contained also discovery information. You may prefer writing your own controller to have more control on what information is returned.

Transaction support in struts2

I am using struts2.0 for my project named online examination system.
I am using traditional JDBC approach in datya access layer. I can't use JPA.
I want to make entire service layer transactional, but i searched for the transaction support in struts2 but didn't get anything.
Although spring provides good support for making service layer transactional.
Please help me on this issue to find out transaction support in struts2.
You are on a wrong track here.Struts2 is only for MVC part and what you are doing at your service layer it has nothing to do with that.
If you want to take advantage of transaction API i suggest you to use either Spring AOP of if i am correct Google Guice also provides a way for AOP.
Whatever you use at your service layer for transaction handling Struts2 is independent of it and out of context

Spring Context Event

I am currently studying Spring.
While reading a Spring book, I met a part regarding Event.
By using context.publishEvent(..), I could trigger the event.
But I don't know what It's exactly for.
I can use other Method instead of using complicated publishEvent.
Please, tell me. thank you.
Spring Events are used to implement publish-subscribe model (or observer pattern) where two not-related parts of code must be somehow connected.
Think of the analogy of web applications where servlet container creates http sessions and your code is informed about this using javax.servlet.http.HttpSessionListener.
Spring uses this mechanism internally. It's much more visible in Spring Security where several parts of the code are informed about e.g., successfull authentication.

Resources