Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no difference between a WebApp and a StandAlone application that uses Spring/Hibernate for it's configuration. You requrie the same JAR files for hibernate. For spring you can do away with the Web oriented JARs but otherwise all the core stuff is required.</p> <p>Place the JARs in a "/lib" folder and add it to your classpath by specifying it in your Manifest.mf as part of your Maven build.</p> <p>To bootstrap a Java application on command line just invoke/load the ApplciationContext to start from your Main class like this...</p> <pre><code>public static void main(String[] args) { ... String[] contextXml = new String[]{ "resources/spring-context.xml", "resources/spring-db.xml" }; ApplicationContext ctx = new ClassPathXmlApplicationContext(contextXml); // invoke your business logic MyBusinessService bean = getBean(MyBusinessService.class); bean.doSomething(); ... } </code></pre> <p>Here's an example DAO</p> <pre><code>import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.stereotype.Repository; @Repository public class MyDaoHibernate extends HibernateDaoSupport { /*** Functional methods ***/ public void save(MyValueObject vo) throws DatabaseException { getHibernateTemplate().saveOrUpdate(vo); } public MyValueObject get(Long id) throws DatabaseException { return getHibernateTemplate().get(MyValueObject.class, id); } /*** Getter &amp; Setters ***/ @Autowired public void initSessionFactory(SessionFactory sessionFactory) { this.setSessionFactory(sessionFactory); } } </code></pre> <p>[EDIT]</p> <p>Good point raised by Yanflea, you'll want to be using a database connection pooling library because this is not provided for you like it is, in a Web App. Download <code>commons-dbcp.jar</code> and add the following to your Spring configuration...</p> <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt; &lt;property name="driverClassName" value="com.sybase.jdbc2.jdbc.SybDriver" /&gt; &lt;property name="url" value="${jdbc.url}" /&gt; &lt;property name="username" value="${jdbc.username}" /&gt; &lt;property name="password" value="${jdbc.password}" /&gt; &lt;/bean&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload