A few weeks (maybe a couple months ago - SO SUE ME!), I figured out how to get a Spring WebApplicationContext into a Vaadin application, so I tried to figure out how to get Hibernate into it with a working DAO to boot. It took a few hours but I think I have this puppy wired. Get it?
Here's a screenshot:
singgihpraditya blog help me get the bits working together. Spring Framework breaks your application into small bits and wire them together using XML config files. So, the magic is really in the config files.
Now since I am using Netbeans as my development IDE, I didn't have to deploy a mySQL database for this. Netbeans has a since Derby "Sample" database - being a sample it already has data.
Don't forget to import the derbyclient.jar. It took me a few to figure that one out. The first time around I thought that my database properties file was source of the error along with the Spring config file.
Here is another screenshot with the web application running on Tomcat.
Aryan, Bhadz, Cholo, Carl, Kim don't hate!
Blog. Repository of ideas/solutions. Web Developer. Data Labandero. Python. TypeScript. Dart. Flutter apps. VB6 free since 2003!
Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts
Sunday, November 7, 2010
Friday, September 3, 2010
Playing with Vaadin + Spring
A few weeks ago, I stumbled on Vaadin Framework and it came with a catchy tag-line:
The thing was not to forget to configure the listener in web.xml file:
After that the WebApplicationContext.xml file in the WEB-INF folder.
With that, you can start doing some really interesting stuff!
Vaadin is a Java Framework for building modern web applications that looks great, perform well, make you and your users happy.That got my attention and so like a kid with a new toy, I started playing around with it and try to do stuff with it. It took me a while, read a few blogs but I have managed to get the hang of Vaadin and even got it to work with Hibernate and Spring. Vaadin with Hibernate was easy to figure out but Vaadin, Spring and Hibernate along with a DAO was a bit of a bitch of figure out but I eventually did. Nicolas Fränkel's blog gave me new insight on how to approach the problem. I sort of agree with his opinions on how to get Vaadin to work with Spring as compared to the techniques posted in the Vaadin wiki page. To quote Nicolas:
The first one uses the Helper “pattern”, a class with static method that has access to the Spring application context. IMHO, those Helper classes should be forgotten now we have DI since they completely defeat its purpose. If you need to explicitly call the Helper static method in order to get the bean, where’s the Inversion of Control?
The second solution uses Spring proprietary annotation @Autowired in order to use DI. Since IoC is all about decoupling, I’m vehemently opposed to coupling my code to the Spring framework. The trick was understanding how to isolate the Spring Context from the Vaadin application. With them separated, all that was needed was configuration files.The thing was not to forget to configure the listener in web.xml file:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>classpath*:WebApplicationContext.xml</param-value> -->
<param-value>WEB-INF/WebApplicationContext.xml</param-value>
</context-param>
After that the WebApplicationContext.xml file in the WEB-INF folder.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:property-placeholder location="classpath*:*.properties" />
<context:annotation-config />
<!-- add autowired or explicitly configured beans here -->
<bean id="myVaadinApplication" class="edu.chuybook.app.MyVaadinApplication"/>
</beans>
With that, you can start doing some really interesting stuff!
Subscribe to:
Posts (Atom)

