In this basic tutorial, I tried to show how spring, hibernate, jsf, richfaces can be used together as a working example. Sources can be downloaded at the end of page.
I am working about 3 days to configure Spring,Hibernate,JSF,Facelets,Richfaces all in one as a maven project with maven jetty plugin. Now it s time to share this configuration as a working example.
First lets look at root pom.xml
ROOT pom.xml
ROOT pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>blogspot.sezera.exampleproject</groupId>
<artifactId>exampleproject</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>exampleproject</name>
<url>http://maven.apache.org</url>
<dependencies/>
<modules>
<module>exampleproject.core</module>
<module>exampleproject.web</module>
</modules>
</project>
We have 2 project. One of them is core and the other is web. Nothing is interesting here.
Core Project
- pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<artifactId>exampleproject</artifactId>
<groupId>blogspot.sezera.exampleproject</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>blogspot.sezera.exampleproject.core</groupId>
<artifactId>exampleproject.core</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Exampleproject Core</name>
<url>http://maven.apache.org</url>
<build>
<resources>
<resource>
<directory>target/generated-resources</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.0.ga</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.5</version>
</dependency>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.4</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2</url>
<layout>default</layout>
</repository>
</repositories>
</project>
java.net repository needed for maven to download Richfaces jars. Other jars will be downloaded from maven.org maven 2 repository.
- dao-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- DATASOURCE DEFINITON-->
<beans xmlns="http://www.springframework.org/schema/beans"
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.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/exampleproject" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<!-- HIBERNATE CONFIGURATION -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>blogspot.sezera.exampleproject.domain.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.max_fetch_depth">1</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop key="hibernate.default_schema">exampleproject</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
</beans>
blogspot.sezera.exampleproject.domain.User class is entity class and it will be persisted to mysql database with hibernate. Because User class using hibernate annotation , instead of xml mapping files, Spring's AnnotationSessionFactoryBean is used for building Session Factory bean. A datasource is defined and defined as a property to sessionFactory bean.
User class is given as a parameter to annotatedClass list property. Here you must add your annotated classes which will be persisted to database.
And another property is hibernateProperties which is actually arguments to hibernate. Here "default schema" is defined as "exampleproject" and hibernate.hbm2ddl.auto set to "update". It means hibernate will update database schema reading hibernate annotated entity classes like "User" class. There is no hbm.xml map files but its names stay same, actually everything done with annotation. So at first, you need to create an empty database schema (create database exampleproject) in mysql database and hibernate will take care of rest.
Actually we can move hibernateProperties property of sessionFactory bean to a file which is named "hibernate.properties" but to keep space minimum it is written inside of dao-context.xml.
User class is given as a parameter to annotatedClass list property. Here you must add your annotated classes which will be persisted to database.
And another property is hibernateProperties which is actually arguments to hibernate. Here "default schema" is defined as "exampleproject" and hibernate.hbm2ddl.auto set to "update". It means hibernate will update database schema reading hibernate annotated entity classes like "User" class. There is no hbm.xml map files but its names stay same, actually everything done with annotation. So at first, you need to create an empty database schema (create database exampleproject) in mysql database and hibernate will take care of rest.
Actually we can move hibernateProperties property of sessionFactory bean to a file which is named "hibernate.properties" but to keep space minimum it is written inside of dao-context.xml.
- User.java
package blogspot.sezera.exampleproject.domain;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="User")
public class User implements Serializable{
private Long id;
private String username;
private String password;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
User class is a basic entity with email, password fields and accessor methods. id attribute is defined as unique identifier for User entity by @Id annotation. Accessor for id is getId() method. Here ids are generating and managing by hibernate. @GeneratedValue annotation can be used for defining id generation strategy but we leave it default here.
- main-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<import resource="dao-Context.xml"/>
<!--SERVICE BEAN DEFINITIONS-->
<bean id="userService"
class="blogspot.sezera.exampleproject.service.impl.UserServiceImpl">
<constructor-arg ref="sessionFactory"></constructor-arg>
</bean>
<!--TRANSACTIAN MANAGEMENT-->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true" />
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- ensure that the above transactional advice runs for any execution
of an operation defined by the userManagementService interface -->
<aop:config>
<aop:pointcut id="managementServiceOperation"
expression="execution(* blogspot.sezera.exampleproject.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="managementServiceOperation" />
</aop:config>
</beans>
main-Context.xml corresponds to Spring's applications classic application-context.xml but we moved entity definition, database and hibernate configurations to dao-Context.xml so we start with importing it.
Every class in service layer has its own interface so UserService interface defined with single createUser method. userService bean is defined with concrete UserServiceImpl class and sessionFactory which is defined in dao-Context.xml before is injected with constructor injection.
Hibernate needs transactions.Without transactions you can't write anything to database.Thanks to aspects transaction behaviour of exampleproject defined easily.A transaction manager bean is defined and sessionFactory instance is given via setter injection.Secondly an advice is defined which says all methods starts with get(like getUserName ...) in a transaction is readonly and other metods are in default transaction behaviour. Critical point is defining where to apply advice in short pointcuts. With aspect expression we define pointcuts for every class under blogspot.sezera.exampleproject.core.service package which is actually service layer.
Every class in service layer has its own interface so UserService interface defined with single createUser method. userService bean is defined with concrete UserServiceImpl class and sessionFactory which is defined in dao-Context.xml before is injected with constructor injection.
Hibernate needs transactions.Without transactions you can't write anything to database.Thanks to aspects transaction behaviour of exampleproject defined easily.A transaction manager bean is defined and sessionFactory instance is given via setter injection.Secondly an advice is defined which says all methods starts with get(like getUserName ...) in a transaction is readonly and other metods are in default transaction behaviour. Critical point is defining where to apply advice in short pointcuts. With aspect expression we define pointcuts for every class under blogspot.sezera.exampleproject.core.service package which is actually service layer.
- UserService.java
package blogspot.sezera.exampleproject.service;
public interface UserService {
void createUser(String username,String password);
}
- UserServiceImpl.java
package blogspot.sezera.exampleproject.service.impl;
import org.hibernate.SessionFactory;
import blogspot.sezera.exampleproject.dao.GenericDaoImpl;
import blogspot.sezera.exampleproject.domain.User;
import blogspot.sezera.exampleproject.service.UserService;
public class UserServiceImpl implements UserService{
private SessionFactory m_sessionFactory;
private GenericDaoImpl<User,Long> userDao;
public UserServiceImpl(SessionFactory sessionFactory) {
m_sessionFactory = sessionFactory;
userDao = new GenericDaoImpl<User, Long>(m_sessionFactory){};
}
public void createUser(String username, String password) {
User user = null;
if(username!=null){
user = new User();
user.setUsername(username);
user.setPassword(password);
userDao.makePersistent(user);
}
}
}
Here Dao pattern is used with generics support. A GenericDaoImpl instance is created for User entity and persisted with makePersistent method which is actually a single line: getSession().saveOrUpdate(entity).
- GenericDao.java
package blogspot.sezera.exampleproject.dao;
package blogspot.sezera.exampleproject.dao;
import java.io.Serializable;
public interface GenericDao<T extends Serializable,ID extends Serializable>{
T makePersistent(T entity);
}
- GenericDaoImpl.java
package blogspot.sezera.exampleproject.dao;
import java.io.Serializable;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
public abstract class GenericDaoImpl<T extends Serializable,ID extends Serializable> implements
GenericDao<T,ID>{
private SessionFactory sessionFactory;
public GenericDaoImpl(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public T makePersistent(T entity) {
getSession().saveOrUpdate(entity);
return entity;
}
protected Session getSession() {
return sessionFactory.getCurrentSession();
}
}
Now we have everything in core side to create a User. So moving to web project.
Web project
- pom.xml
<?xml version="1.0"?>
<project>
<parent>
<artifactId>exampleproject</artifactId>
<groupId>blogspot.sezera.exampleproject</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>blogspot.sezera.exampleproject.web</groupId>
<artifactId>exampleproject.web</artifactId>
<packaging>war</packaging>
<name>exampleproject.web Maven Webapp</name>
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<build>
<finalName>exampleproject.web</finalName>
<!--MAVEN JETTY PLUGIN-->
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>blogspot.sezera.exampleproject.core</groupId>
<artifactId>exampleproject.core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>1.2_02</version>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.11</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2-b19</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-ui</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repository.jboss.com</id>
<name>Jboss Repository for Maven</name>
<url>http://repository.jboss.com/maven2/</url>
<layout>default</layout>
</repository>
</repositories>
</project>
- UserController.java
package blogspot.sezera.exampleproject.controller;
import blogspot.sezera.exampleproject.service.UserService;
public class UserController {
private UserService service;
private String username;
private String password;
public UserController(){
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void setService(UserService service) {
this.service = service;
}
public void createUser(){
service.createUser(username, password);
}
public UserService getService() {
return service;
}
}
- EmailValidator.java
package blogspot.sezera.exampleproject.validator;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
public class EmailValidator implements Validator{
public void validate(FacesContext arg0, UIComponent arg1, Object arg2)
throws ValidatorException {
String email = arg2.toString();
if(email.contains("@")==false){
//error message
ResourceBundle bundle = ResourceBundle.getBundle("messages",arg0.getCurrentInstance().getViewRoot().getLocale());
FacesMessage msg = new FacesMessage(bundle.getString("emailNotValid"));
throw new ValidatorException(msg);
}
}
}
To validate user email address when creating user I have created a basic EmailValidator. It validates if user email address contains "@". If not a ValidatorException is thrown.
- messages_en_US.properties
emailNotValid=E-mail is not valid
- newUser.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<head>
<title>New User</title>
</head>
<body>
<f:view>
<h:form>
<table>
<tr>
<td><h:outputLabel value="UserName "></h:outputLabel></td>
<td><h:inputText id="email" value="#{userController.username}">
<f:validator validatorId="emailValidator" />
<a4j:support event="onkeyup" requestDelay="300" reRender="output"/>
</h:inputText>
</td>
<td>
<h:outputLabel id="output">
<h:message for="email"/>
</h:outputLabel>
</td>
</tr>
<tr>
<td><h:outputLabel value="Password"></h:outputLabel></td>
<td><h:inputSecret value="#{userController.password}"></h:inputSecret><br/></td>
</tr>
</table>
<h:commandButton value="Create User" action="#{userController.createUser}"></h:commandButton>
</h:form>
</f:view>
</body>
</html>
When user started to write his email address, page send an AJAX request to server in every 300 second and EmailValidator executes. If there is an error in user email, page renders an error message right of user email input text area.
- web.xml
<?xml version="1.0"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>ExampleProject Web</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/main-Context.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>classic</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
- faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<application>
<resource-bundle>
<base-name>messages</base-name>
<var>msgs</var>
</resource-bundle>
<locale-config>
<default-locale>en_US</default-locale>
</locale-config>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
</application>
<validator>
<validator-id>emailValidator</validator-id>
<validator-class>
blogspot.sezera.exampleproject.validator.EmailValidator
</validator-class>
</validator>
<managed-bean>
<managed-bean-name>userController</managed-bean-name>
<managed-bean-class>
blogspot.sezera.exampleproject.controller.UserController
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>service</property-name>
<value>#{userService}</value>
</managed-property>
</managed-bean>
</faces-config>
HOW TO RUN EXAMPLEPROJECT
- download source codes without jars.
- mvn clean install under root directory
- create an empty database named "exampleproject" in mysql
- Under exampleproject.web execute: mvn jetty:run
- http://localhost:8080/exampleproject.web/newUser.faces
SCREENSHOT
DOWNLOADS
source codes
pdf version
REFERENCES
AUTHOR
Sezer Akar
Blog
39 comments:
Thank you for that interesting article. I've been looking for a quick setup guide for playing with richfaces, spring, hbn, facelets and maven and your project fits perfectly.
Simply Great.
I finaly found what I was looking for. Thank you man, for posting it.
I'm happy that it fits in your need.
Great tutorial! Thx!
Thanks dude. It is one of the good tutor.
You are great! A true life saver.. The first example I found in this regard which works, thanks to resolving all the Maven dependencies.
So..you need 3 days to configure, so you can build that simple thing. Goodbye java world!
thank you for that interesting article, I've found what I was looking for.
I've run it, after that, I followed the same code to run it in netbeans IDE and with Apache Tomcat.
At this moment, I can deploy and run it but when I execute the creation user action, I meet this Exception:
javax.servlet.ServletException: #{userController.createUser}: org.hibernate.HibernateException: No TransactionManagerLookup specified
Can you help me please ?
When I ran it, I got the following error:
Mar 10, 2009 6:43:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Access denied for user 'root'@'localhost' (using password: NO)
Mar 10, 2009 6:43:42 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: could not get database metadata
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
Is there some other db setup step that I missed?
I defined a password for the root account and updated daoContext.xml accordingly, but it looks like the password there is not being applied
Hi mjoud.
I didn't try to deploy war to tomcat.Are you facing same issue now?
Hi Reuben F,
db settings only in dao-context.xml
.......
property name="url" value="jdbc:mysql://localhost/exampleproject"
property name="username" value="root"
property name="password" value=""
...........
as you see default username root, password "". So if you change these settings make sure you did "mvn clean install" from top of core and web projects then "mvn jetty:run" inside web project. It should be worked.
I had updated the daoContext.xml but
had not done the 'mvn clean install' first. That did the trick.
You have to generate .war file with "mvn clean install" when you change xml configuration files.
Eline sağlık çok güzel bir tutorial olmuş=]
I tried to deploy the war file in tomcat, I cannot access newUser.faces. The error message I got is under below:
exception
javax.servlet.ServletException: Servlet.init() for servlet Faces Servlet threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)
root cause
java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory
javax.faces.FactoryFinder.getFactory(FactoryFinder.java:263)
javax.faces.webapp.FacesServlet.init(FacesServlet.java:142)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)
I can successfully using jetty:run-war to run this example target. Does somebody know what is the problem?
Thanks,
Frank
Hi Frank,
It seems application didn't start well in tomcat in your case. Please be sure that all dependencies (jsf,spring,etc.) available for tomcat so faces context can startup. You can google a bit for tomcat+jsf+spring.
LOVELY ARTICLE.
Its Great to see such a great service, since I faces alots of dependency issues, with SPRING, HIBERNATE and RiCHFACES integration. Lost 2 productive days.
THis example gives 20mins solution, to tacle the same.
Thanks alot.
you are welcome.
Hello
Thanks for your post!
I have run your example succesfully. Now i wish to create an eclipse (Ganymede) project using your directory structure. I try to link your source files to the eclipse project but i fail. Do you know an easy way to do that?
Thanks
hi,
you are welcome. try mvn eclipse:eclipse command before importing project via File>Import>Existing Projects into Workspace.
Hi,
thanks for your quick anwser. I allready have try that command but i notice that it creates like two separate projects (one java project and one web poject) and that there is no folder I can use as the web application context. Do you understand what i mean?
Thanks a lot
Hi. Yes it creates 2 separate projects. 1 for core and 1 for web.
you can start web context with mvn jetty:run on web project. Also you can deploy .war file (which is under web project->target folder) to a container(like tomcat) If we talk about project settings web project is the place where you should add your .xhtml,.jsp files and jsf controllers etc.
Hi All,
I had try this example on windowXP work fine. But When I deploy on ubuntu8.10, I get exception: java.util.zip.ZipException: error in opening zip file,...
any ideal,
Thanks,
hvt_kg
Hi hvt_kg,
In which phase you got this exception?
Hi Sezer Akar,
That's phase when I start server with command:
mvn clean jetty:run
thanks,
hvt_kg
By the way, I using maven version 2.0.9 and jdk1.6.0_06. that is all!
I tried to implement an app as per your article, it worked out very well, thanks for such a nice article. I have one question for you, I am using MySQL database .. and i am using sessionfactory in dao, using advices for transactions ... when i insert a record, it gets inserted but i have noticed that records are getting deleted automatically after some time (15-30 minutes) .. I am assuming that somehow the transactions are rolling back for me .. is it because i have not written CMT stuff for the app server(IBM), and i am using the jdbc per the article ...
org.springframework.jdbc.datasource.DriverManagerDataSource
Can you point me to somthing useful, kinda stuck with it .. Many thanks for the help ..
Hi hvt_kg,
Sorry for late reply. I think it is because app war zipped in windows like env but trying to deploy in linux env. Try getting source code and compile,install,run in linux. It should be ok.
Hi Sanjay,
It seems you have changed app code and I don't know details. But rolling back after 15-20 min? it seems weird to me it may contain another error.
Hi Sezer,
Thanks for getting back to me .. I know it sounded weird (10-15 min) but it was happening, later i realized even the app server restart was removing the records ..I think i was not handling the transactions correctly ..I was using this in hibernate ..
hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup=org.hibernate.transaction.WebSphereExtendedJTATransactionLookup
And was also mentioining the below in Spring ..
org.springframework.transaction.jta.JtaTransactionManager
bean property name="autodetectTransactionManager" value="false"
/bean
I think the issue was my websphere version (6.1) which does not have support for WebsphereUOWTransactionManager class .. so i was trying various ways ..The above written code works jsut fine if i remove the hibernate lines and just use Spring lines for transactions ..
One last question i had for you was, Is this the right way of doing it, I mean i should not be mentioning anything inside Hibernate for transactions, since Spring will do all transaction handling .. so the only entry for spring
bean id="myTxManager" class="org.springframework.transaction.jta.JtaTransactionManager"
property name="autodetectTransactionManager" value="false"
bean
should be enough to handle the transactions .. is this correct ?
Or do i need to do anything else to take care of transactions properly ..As always thanks for the help ..
Also is it ok if i use JtaTransactionManager mentioned above, since WebsphereUOWTransactionManager does not seem to work with this server version... is there a downside, I wish i could upgrade websphere to a newer version but I am not really sure on that .. so thought i wil check once .
I want to use SKINS of springfaces
integrated with richfaces ... please advise
Very good article.
Appreciated your effort to the forum.
Thanks.
If possible could you please integrate seam with these technologies ?
This was great start up for me.
I tried some changes like
1. Adding @Controller ( ended up with error message "annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations)" ).
2. request received by controller, controller populates data and sends that data to xhtml page.
But no luck. Could you give some ideas ?
your java version should be >=1.5
Hi, it looks like a broken link when i try to download source files.
thx
Link is offline. Please up to another server. Thanks.
The link sourcecode is offline. Please upload to another server. PLEASE!...
HI Sezer your 2 links source codes
and pdf version is empty :(
HI Sezer first thnks for this docmunt but ur 2 links is empty now :(
Hi guys,
Thanks for your interest, but I lost these files, it has been 5 years!. There should be more convenient ways to handle these kind of integration issues today. Try groovy&grails maybe or javaee7?
Take care
Sezer
Post a Comment