How to select the right version of spring, struts and hibernate, what's the difference?
I want to select the lastest frameworks to integrate spring, struts and hibernate, but seems that there are so many versions out there,开发者_运维问答 and their api are different too, so I was confused that how can I select the right version to integrate them ? And What's the differences between them ?
For example, can I have the following integration: Spring Framework 3.0 Struts 2.0 Hibernate 3.2
As I am new to these frameworks, please point me the right direction, and let me know how can I select the right version to work on?
Thanks in advance !
Here is what I do hope it helps others (first how I set up in Netbeans, at the end is a pom for the general approach).
Note when I say add a certain jar I mean, in Netbeans:
- Right click Dependencies, Select "Add Dependency..."
- In the Query field ender the first part the jar not including the version, ie for: spring-orm-3.0.5.RELEASE.jar just enter spring-orm, the search will show several different results but only "org.springframework : spring-orm" contains version 3.0.5.RELEASE so that is the one to use... If this seems too wishy washy, the pom in this answer provides the exact co-ordinates so feel free to use those.
Create a new Maven Web application. Follow: http://struts.apache.org/2.2.1.1/docs/create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html
add stuts2-spring-plugin (v 2.2.1.1) - this then adds a number of unneeded jars in the 2.5 series, right click these files and exclude them. - now add the following:
spring-orm-3.0.5.RELEASE.jar
spring-tx-3.0.5.RELEASE.jar
spring-web-3.0.5.RELEASE.jar
slf4j-log412-1.5.5.jar (NOTE: there are later version but you must use this version)
I always add struts2-convention-plugin-2.2.1.1.jar (but this is optional).
For hibernate dependencies add:
hibernate-annotation-3.5.1-Final.jar
hibernate-entitymanager-3.5.1-Final.jar
hibernate-jpamodelgen-1.1.1.Final.jar
Here is my pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aerose</groupId>
<artifactId>PartGroupMaster</artifactId>
<version>2011.04.12</version>
<packaging>war</packaging>
<name>PartGroupMaster Web App</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
</properties>
<repositories>
<repository>
<id>JBoss Repo</id>
<url>http://repository.jboss.com/maven2</url>
<name>JBoss Repo</name>
</repository>
<repository>
<id>ibiblio mirror</id>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</repository>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
<repository>
<url>http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo</url>
<id>eclipselink</id>
<layout>default</layout>
<name>Repository for library Library[eclipselink]</name>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.2.1.1</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.2.1.1</version>
<exclusions>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.15</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.1-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.1-Final</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-config-browser-plugin</artifactId>
<version>2.2.1.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.1.1.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>PartGroupMaster</finalName>
</build>
</project>
This provides a rather current version of Struts2, Spring and Hibernate. Then comes the fun of configuring the configuration files... but that's for another question.
If you're possibly using a build system like Maven2, it can resolve all the dependencies for you. If you don't you can look for maven config files and just copy the version numbers from there. Also all the specific versions can be downloaded manually from one of the maven repositories online.
Maven configuration files are typically named pom.xml
and contain among other things all the dependencies for a project. Many people publish their pom files online to help out others, however it's not difficult to really write one yourself.
For example here you have an example configuration. It's probably little dated, but for just playing with the framework it should do:
http://www.mkyong.com/struts2/struts-2-spring-hibernate-integration-example/
Spring, Struts 2 and Hibernate all work together nicely.
If you are starting on a new project you should use the latest of each: Spring 3.0.5, Struts 2.2.1.1, Hibernate 3.6.3
If you use Maven 2 then you really don't need to worry about these things.
If you are starting from scratch, I would further recommend you to check out tools like Spring Roo or AppFuse. These tools do a great job at generating the basic application scaffolding for you and use the correct versions of Spring, Struts and Hibernate behind the scenes.
One other suggestion I would have is don't go for lot of frameworks i.e. if you already have decided to use Spring then go with Spring MVC instead of Struts unless you have legacy that needs to be supported.
You may also benefit from this stack overflow discussion.
Hope that helps.
精彩评论