Why does Struts 2 depend on springframework? - java

I downloaded the latest version of Struts 2 to upgrade our current set of jars, and looking at the huge list of jars that come with Struts 2, I want to only include the ones that are truly required.
I had a look at the Struts 2 dependency tree and the Struts 2 compile dependencies, but I'm having trouble understanding what they mean for my application. I don't think we use anything in org.springframework (doing a workspace-wide search), but is that enough to know whether we can exclude those jars?
Is it as simple as looking at the "optional" column of the compile dependencies table from the 2nd link above? Of the optional ones, how do you know when you need them and when you don't? There are so many....

The Struts2 project has a compile dependency on Spring framework. But this doesn't mean that you need a spring framework jars to your project. As you mentioned these dependencies are optional. It means they are required if you use some features of Struts2 that depend directly on Spring. You can use Maven to resolve dependencies for your project's pom.xml. If you want to view/analize a dependency tree you can use eclipse m2eclipse plugin. Analogous visualization tools available in other IDEs. The same as invoking manually mvn dependency:tree.

It doesn't depend on spring framework.
Check here
Step 3 - Add Struts 2 Jar Files To Class Path
to see the minimum required libs for a strtus2 project.

Struts2 is using the spring framework only for the tests and compiling during build.
Beside this only the Struts2 Spring plugin has a dependency to the spring framework.
If you are not using this plugin you should not have any spring dependencies in your project.

struts2 has a dependency on spring framework because of some decent core features.
Dependency injection and AOP are the widely used features of spring framework with struts2.
while struts2 framework is rich in UI and MVC view but these are the components that makes struts2 dependent on spring.
Spring framework's security feature,JDBC,transaction management are the other module that can be used with struts2.
thanks,
Amit Kumar

Struts2 does not have any dependency on Spring. However, when you take a look at struts 2 library, it contains Spring related jar. This is done to add additional support to integrate Struts and Spring and to use nice to have features/modules of Spring like DI, AOP, transaction etc. It is completely optional to exclude those jars and to go ahead with conventional Struts framework. Also as there is no incremental development for struts like bringing struts 3 in market. Way to go forward is to integrate struts with Spring.

Related

Have I to put spring-mvc.jar in my classpath to create a Spring MVC project?

I am pretty new in Spring. If I want to implement a Spring MVC project have I to explicitly put the spring-mvc.jar file into my classpath? From what I know the Spring MVC project is not part of the Spring Core.
Is it right?
You can go many ways but I'll suggest you to learn a build automation tool like maven or gradle. It will take care of everything related to dependency management. Here's a good resource to get started https://spring.io/guides/gs/gradle/

bean dependency diagram in eclipse for a java config based spring project

I'm using STS/GGTS 3.0.0 in eclipse, my spring project is a mix of java based, and xml based spring configuration.
I'd like to see some dependency diagrams of the spring beans, I can't figure out how to do that.
any ideas?
Kind Regards

How to find out which dependencies need to be included?

I'm fairly new to Java/Spring and am trying to put together a simple app which will include some basic CRUD operations and I'd like to use Hibernate for data access.
I'm using Maven as my build tool. My question is: how can I find out which dependencies are required to use Hibernate? For example, I'm using Spring 3.0.6, but how would I know what version of Hibernate to use with that version of Spring? More over, if there are multiple possible Hibernate dependencies, how would I know which ones to include for the functionality I need? So far this seems to be partially reading documentation and partially trial and error.
Is there a definitive way of knowing which Maven dependencies to use with certain version of other dependencies? Any which dependencies to use for particular bits of functionality?
Thanks,
James.
I follow these steps when starting to use a new framework:
Go to framework's web site. In your case hibernate web site and try to find latest (or a specific) version. For hibernate it is 3.6.8-Final at the time of writing.
Search for a maven dependency definition on the framework web site. If you can not find any dependency definition, them simply google for "frameworkname _version_ maven dependency" and you'll most probably find necessary definition, as well as the necessary repository information. For example you can find the dependency definition for hibernate on mvnrepository.com and necessary artifact repository information on Hibernate 3.6.8 release page:
The artifacts have all been published to the JBoss Nexus repository under the org.hibernate groupId at http://repository.jboss.org/nexus/content/groups/public-jboss/
The question of which dependencies are necessary and which are optional depends entirely on the framework to be used. So for example in order to use hibernate, as stated on Hibernate Quick Start Guide:
hibernate-core: The main artifact, which contains all the Hibernate classes, in packageorg.hibernate. You need these to build applications using the native Hibernate APIs. It includes capabilities for using native Hibernate mapping in hbm.xml files, as well as annotations.
About compatibility issues (which version of hibernate is compatible with spring 3.0.6), all I can say is you have to read about integration manuals for those frameworks. Since Spring and Hibernate are two exclusively distinct frameworks, I don't think you can find a constant location to look for version compatibility matrix or something like that.
The purpose of Maven is to avoid handling dependencies by hand. Just choose which version of Hibernate to use and include it in your pom; Spring supports many different versions.
If you know what parts of Spring you want to use, just include those parts in your pom; they'll include their own requirements.
Is there a specific module and/or version combination you're having an issue with?
The only way to know for sure that you've got all dependencies is by running your app.
Maven resolves for you transitive dependencies so you can quickly detect missing ones by compiling the java code.
However, in a web app there are many dependencies that are required in runtime only, so they are not detected at compilation time.
you can find out the dependencies by running mvn dependency:tree and analyze if they are required or not by running mvn dependency:analyze.
Taking the newest ones usally works as long as they are stable.
Start with hibernate and spring core, context, tx.
After you added some could you will probably recognize that something else is missing.
Try and error doesn't sound good, but its working pretty well for spring dependencies.

I am confused with Hibernate Spring

I am rookie into Java and I am directly thrown into Hibernate and Spring. I have attended some training classes and I am following documents online from random forums and trying to run a test project. I have some set of questions to be answered.
What is the latest version of Hibernate that has come and where do I download all the dependent jars in one place?
What is the latest version of Spring that is out there?
Any links/blogs that shows me to configure a hello world or a similar implementation would be of great help with the latest versions of Spring and Hiberante!!
Thanks.
The project web page says it is Spring 3.0.5 Release
The project web page says it is Hibernate 3.6.1 Release
Hibernate and Spring tutorial
Rest you will find using some web search like google.com or bing.com or altavista.com
I highly recommend you check out Spring Roo. There is a super duper quickstart.
Although its touted for doing Code and JSP scaffolding I find its biggest benefit is setting up your project in a very canonical and java/spring best practice setup.
It will setup maven and all the dependencies you will need. The default Maven Pom file alone is a big time saver.
If you don't want to use Roo you can easily just strip it out of your Maven pom file after your done doing the initial scaffolding.
The other option is using a Maven Archetype like AppFuse but I haven't used this in quite some time and I find Roo easier.
What I don't recommend is wasting your time writing an Ant script and then trying to cobble together all the dependencies.

What is Spring's Minimum Dependencies for Dependency Injection?

What are the minimum dependencies required to just use Spring's dependency injection (core framework only)? I'm using Spring for a standalone application, and I'd like to minimize the number of dependencies that I have to ship with the application.
I suppose I could systematically remove a Jar and see if the application breaks, but it would be much better if someone had a definitive answer.
Oh, and I'm using Spring 2.5.
Check out the readme.txt that comes with the download of Spring 2.5.
Assuming you don't have AOP, JDBC, Transactions, or ORM, then your best bet is probably:
spring-core
spring-beans
spring-context
If your are using maven then only spring-context is needed in your pom.xml, it depends on aop, beans, core, expression and asm

Categories

Resources