Skip to content

Struts Spring Hibernate Integration

November 5, 2012

Struts with Spring:
Spring with Struts scenario: (Integrating Spring with other web frameworks – Struts)
We can acquire a particular web framework such as Struts, while at the same time being able to enjoy the benefits afforded by Spring in other areas such as data access, declarative transaction management, and flexible configuration.
To INTEGRATE your Struts 1.x application with Spring, you have two options:
Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependencies in a Spring context file.
Subclass Spring’s ActionSupport classes and grab your Spring-managed beans explicitly using a getWebApplicationContext() method.
 
 Reference: 0) http://viralpatel.net/blogs/tutorial-struts-spring-framework-example-in-eclipse/
                 1) http://www.mkyong.com/struts/struts-spring-integration-example/
                 2) http://www.javabeat.net/2007/05/integrating-struts-with-spring/

Spring with Hibernate:

Spring configuration file will have:

Pom.xml Dependencies:

Need to mention Spring Dependencies and Hibernate Dependencies as below:

        <!– Spring framework –>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
 
        <!– Spring AOP dependency –>
        <dependency>
            <groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>

<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate3</artifactId>
<version>3.2.3.GA</version>
</dependency>
 
<!– Hibernate annotation –>
<dependency>
<groupId>hibernate-annotations</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.GA</version>
</dependency>

Spring Config file should have the below code:

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManagerName" value="java:/TransactionManager"/>
</bean>

or if you are using Websphere, then

<bean id=”transactionManager”  class=”org.springframework.transaction.jta.WebSphereUowTransactionManager” />

About these ads

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: