A Techno Blog, mainly about Java

SourceBeat Chapter

Based on post a few months back on a positive experience with the Spring Live chapter 2 [tss] , thought I’d finally try it out. [forum] [wiki FAQ]
JAVA_HOME is C:\j2sdk1.4.2_05\
ANT_HOME is C:\apache\apache-ant-1.6.2
CATALINA_HOME is C:\apache\jakarta-tomcat-5.0.27
PATH has C:\apache\apache-ant-1.6.2\bin;C:\j2sdk1.4.2_05\bin; C:\apache\jakarta-tomcat-5.0.27\bin extract to C:\sourcebeat\

C:\sourcebeat\equinox>ant new

copy  C:\sourcebeat\myusers to CATALINA_HOME\webapps

CATALINA_HOME\conf\tomcat-users I added
  <user username="admin" password="admin" roles="manager"/>

C:\apache\jakarta-tomcat-5.0.27\webapps\myusers>ant list

C:\apache\jakarta-tomcat-5.0.27\webapps\myusers>ant deploy

went into manager http://localhost:8080/manager and add myusers directory

http://localhost:8080/myusers/&nbsp; , get page with:
"Equinox is a lightweight version of AppFuse. I was inspired to create it when looking at the struts-blank and webapp-minimal applications that ship with Struts and Spring, respectively. These "starter" apps were not robust enough for me, and I wanted something like AppFuse, only simpler. "

Code up UserDAO ,  User, User.hbm.xml   [Spring live source code]

Here, I found I must change the url  in the WEB-INF/applicationContext.xml which I changed to
<property name="url"><value>jdbc:hsqldb:C:/apache/jakarta-tomcat-5.0.27/webapps/myusers/db/appfuse</value></property>

Also, in this file set the MappingResources property value to indicate the location of

C:\apache\jakarta-tomcat-5.0.27\webapps\myusers>ant deploy reload

C:\apache\jakarta-tomcat-5.0.27\webapps\myusers>ant browse

The place where you configure a Java EE app to use Spring is in the web.xml file. What you do is
set the listener :

The next step is configuring spring with hibernate. We will look in the applicationContext.xml
The session factory bean that has a dependency on data source bean:

<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
        <property name="dataSource"><ref local="dataSource"/></property>
        <property name="mappingResources">
        <property name="hibernateProperties">
            <prop key="hibernate.dialect">net.sf.hibernate.dialect.HSQLDialect</prop>
            <prop key="">create</prop>

The data source bean:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property>
        <property name="url"><value>jdbc:hsqldb:C:/apache/jakarta-tomcat-5.0.27/webapps/myusers/db/appfuse</value></property>
        <property name="username"><value>sa</value></property>
        <property name="password"><value></value></property>

The transaction manager bean which depends on the session factory:

<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>

Now we code up UserDAOHibernate  [Spring live source code]

In applicationContext.xml we create a  relationship to the UserDAOHibernate :

<bean id="userDAO" class="org.appfuse.dao.hibernate.UserDAOHibernate"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean>

[myusers w/eclipse]

Some Spring links:



July 12, 2005 - Posted by | IoC

No comments yet.

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: