Wednesday, August 24, 2011

The content of element type must match

Problem :


I have the following error :
The content of element type "filter" must match  "(icon?,filter-name,display-name?,description?,filter-class,init-param*)".

Here is an extract of my web.xml :
<filter> 
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class> 
</filter> 


Solution :

In fact, the solution is in the message.The message said that there is an order in the tags filter-mappings.
You have to put first filter-name then url-pattern or servlet name.
So you have to correct like that :

<filter> 
    <filter-name>richfaces</filter-name>
    <display-name>RichFaces Filter</display-name>  
    <filter-class>org.ajax4jsf.Filter</filter-class> 
</filter> 

An important note, this error appear because I put the following dtd in my web.xml :

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>

Or it's not the last dtd.Now it has change and it seems that the good manner is the following :

<?xml version="1.0"?>
<web-app version="2.5" 
    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-app_2_5.xsd">

Friday, August 19, 2011

GWT and Eclipse : Unable to find a module


Problème :

When I launch my application in Eclipse, I have the following error :

Loading modules
   de.toolforge.googlechartwrapper.googlechartwrapper
      [ERROR] Unable to find 'de/toolforge/googlechartwrapper/googlechartwrapper.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] shell failed in doStartup method

I check all of my line of code and there is no references to this module.

Solution :

In Eclipse :

Run -> Run Configurations
Go in  Arguments tab.

Then you have to delete the bad module.For me :
   de.toolforge.googlechartwrapper.googlechartwrapper

Thursday, August 18, 2011

GWT : compilation error with Map


Problème :

         In your code, you declare Map&lt;Integer, Integer&gt; map = new HashMap&lt;Integer, Integer&gt;
and you have the following error  :

         [ERROR] Line 23: No source code is available for type com.google.gwt.dev.util.collect.HashMap&lt;K,V&gt;; did you forget to inherit a required module?


Solution :

Map collections works with Object.However Object isn't serializable.So to work, you have to pass the following arguments in comments :@gwt.typeArgs &lt;java.lang.Integer,java.lang.Integer&gt;
to define the contents of your map :


public class ChartData implements IsSerializable {

  /**
   * This field is a Map that must always contain Strings as its keys and
   * values.
   * 
   * @gwt.typeArgs &lt;java.lang.Integer,java.lang.Integer&gt;
   */
  public Map data;
  
  public ChartData() {
  }
}


Then you can use your Map like that :

CharData charData = new CharData();
charData.data.put(12,13);

Ref :

Tuesday, August 16, 2011

[WARN] Candidate class for JDOQL single-string query (User) could not be resolved User


Problème :

[WARN] Candidate class for JDOQL single-string query (User) could not be resolved User

Solution :

I have not instantiate my User class because I call it with a static method :
User.myMethod();

And in my Method, I make the following request :
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(User.class);

To resolve the problem, I do the following :

User myUser = new User();
myUser.myMethod(); // myMethod n'est plus statique

Friday, August 12, 2011

How to log with GWT

In your test.gwt.xml file, you have to add the following :


 &lt;inherits name="com.google.gwt.logging.Logging"/&gt;
  &lt;set-property name="gwt.logging.logLevel" value="INFO"/&gt;          # To change the default logLevel
  &lt;set-property name="gwt.logging.enabled" value="TRUE"/&gt; 

In your java file :


  • Import the logger :

import java.util.logging.Logger;


  • Declare logger variable :

private static final Logger logger = Logger.getLogger(WeightManager.class.getName());


  • Call logger methods :

logger.info("========&gt;TEST !!!!");

Note : Logging works only in client side (so in client package).In server side it doesn't work for me so if I found something, I will publish a post.

Sunday, August 7, 2011

JBoss 7 and JEE6 a good way to update your knowledge


You want practice JEE6 with CDI and other stuff ...
A good way to do taht it's to download the new JBoss application server (JBOSS 7) and to download examples.
Tutoriels show simple examples (Hello world application, login application ...) which uses JEE6 features with Maven 3.In my mind it's a esay and good way to test theses technos and there is a good documentation.
Moreover, JBOSS 7 appears to be very fast !

Friday, August 5, 2011

Java7 available for the maven compiler plugin.



Hi ! This morning I tried to compile my project with Maven and the JDK7 and it works.
Here is my settings.xml extract :


Wednesday, August 3, 2011

Bug on JAVA 7


Now, the community talk a lot about a bug on JAVA 7.I found on the web a good summary of the situation :

- yes java 7 has a bug
- Yes It's a problem for Lucene and certainly other project
- No you don't have to avoid Java 7
- Yes you have to wait before going into production
- Yes you can uncheck theses optimisations and have a  JAVA 7 with no bug.
http://www.infoq.com/news/2011/08/java7-hotspot

Sunday, July 31, 2011

Java 7 Warning with the behaviour of WatcherService ?



I look at new functionnality for WatcherService.So I created a directory and I watch for events like files created or deleted or modify.I follow the example from http://blogs.oracle.com/thejavatutorials/entry/watching_a_directory_for_changes
I was surprised for an unexpected  behaviour with WatcherService :


I make the following :
mkdir ~/tmp
touch ~/tmp/toto


Then I watched for events in ~/tmp/toto and it works fine.

Then I do the following :

mv ~/tmp ~/tmp.old
touch ~/tmp.old/titi


I look at events and there is events ! However I move the directory so the program should be throw an exception because of reset methods() but no !
So I post a message (It's the first time I post a message on the Oracle's web site !!!! ) and I wait for an answer ...
I will see if I post a good note ....


Here is the example source code form Oracle'sblog :

for (;;) {

    //wait for key to be signaled
    WatchKey key;
    try {
        key = watcher.take();
    } catch (InterruptedException x) {
        return;
    }

    for (WatchEvent event: key.pollEvents()) {
        WatchEvent.Kind kind = event.kind();

        //This key is registered only for ENTRY_CREATE events,
        //but an OVERFLOW event can occur regardless if events are
        //lost or discarded.
        if (kind == OVERFLOW) {
            continue;
        }

        //The filename is the context of the event.
        WatchEvent ev = (WatchEvent)event;
        Path filename = ev.context();

        //Verify that the new file is a text file.
        try {
            //Resolve the filename against the directory.
            //If the filename is "test" and the directory is "foo",
            //the resolved name is "test/foo".
            Path child = dir.resolve(filename);
            if (!Files.probeContentType(child).equals("text/plain")) {
                System.err.format("New file '%s' is not a plain text file.%n", filename);
                continue;
            }
        } catch (IOException x) {
            System.err.println(x);
            continue;
        }

        //Email the file to the specified email alias.
        System.out.format("Emailing file %s%n", filename);
        //Details left to reader....
    }

    //Reset the key -- this step is critical if you want to receive
    //further watch events. If the key is no longer valid, the directory
    //is inaccessible so exit the loop.
    boolean valid = key.reset();
    if (!valid) {
        break;
    }
}




Sunday, July 24, 2011

cvc-complex-type.2.4.a: Invalid content was found starting with element 'display-name'

Problem :

cvc-complex-type.2.4.a: Invalid content was found starting with element 'display-name'. One of '{"http://java.sun.com/xml/ns/javaee":servlet-class, "http://java.sun.com/xml/ns/javaee":jsp-file}' is 
 expected.

In Eclipse, I have the following target (display-name) in red :

web.xml :
  <servlet>
<servlet-name>monitor</servlet-name>
<display-name>monitor</display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/monitor-servlet.xml</param-value>
    </init-param>
<load-on-startup>1</load-on-startup>
  </servlet>

Solution:

You have to put the tag display-name first.

  <servlet>
<display-name>monitor</display-name>  
<servlet-name>monitor</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/monitor-servlet.xml</param-value>
    </init-param>
<load-on-startup>1</load-on-startup>
  </servlet>

Note : In my google project http://code.google.com/p/lin-mon-webapp/, I have committed a web.xml with no validation error (I just make right click to be sure not having validation error)

Monday, July 18, 2011

java.lang.ClassNotFoundException: javax.faces.FacesException

Problem :

In JBoss 6.0.0 when I deploy my war, I have the following error :

java.lang.ClassNotFoundException: javax.faces.FacesException 

Solution :

I've add following Maven dependencies :

<dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.0.0-Beta2</version> </dependency>

Friday, July 15, 2011

Create a database with a user

Just a simple reminder ...

mysql>mysql -u root
mysql>create database db;
mysql>GRANT ALL ON db.* TO 'integration'@'localhost' IDENTIFIED BY 'integration';
mysql>GRANT ALL ON db.* TO 'integration'@'%' IDENTIFIED BY 'integration';
mysql>flush privileges;
mysql>quit

Then you can do on localhost or  on your IP:

mysql -u integration -p 
mysql -u integration -h 127.0.0.1 -p

Thursday, July 7, 2011

java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener

Problem :

In JBoss 6.0.0 when I deploy my war, I have the following error :

java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener 

Solution :

I've add following Maven dependencies :

<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-impl</artifactId>
  <version>2.0.0-Beta2</version>
</dependency>
<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-impl</artifactId>
  <version>2.0.0-Beta2</version>
</dependency>

Tuesday, July 5, 2011

ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory

Problem :

When I deploy my war on JBoss 6.0.0, I have the following error :

java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory


Here is an extract of my Maven pom.xml file :

   <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-annotations</artifactId>
     <version>3.4.0.GA</version>
     <exclusions>
       <!-- Exclude Commons Logging in favor of SLF4j -->
       <exclusion>
         <groupId>org.apache.commons</groupId>
         <artifactId>com.springsource.org.apache.commons.logging</artifactId>
       </exclusion>
   </dependency>

Solution :

You have to exclude xml-apis because there is a conflict between xml-apis and librairies into JBoss (xeres-impl).
So you have to do the following :
     <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-annotations</artifactId>
     <version>3.4.0.GA</version>
     <exclusions>
       <!-- Exclude Commons Logging in favor of SLF4j -->
       <exclusion>
         <groupId>org.apache.commons</groupId>
         <artifactId>com.springsource.org.apache.commons.logging</artifactId>
       </exclusion>
   <exclusion>
     <groupId>xml-apis</groupId>
     <artifactId>xml-apis</artifactId>
   </exclusion>        
     </exclusions>
   </dependency>

Sunday, July 3, 2011

Eclipse : Can not find the tag library descriptor for "http://java.sun.com/jsf/core"

Problem :

In Eclipse, I have the following error : Can not find the tag library descriptor for "http://java.sun.com/jsf/core"

Solution :

I add this dependencies for having the jat in Eclipse classpath :

<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>2.0.0-Beta2</version>
</dependency>

Saturday, July 2, 2011

Can not find the tag library descriptor for "http://java.sun.com/jsf/html"

Problem :

I have the following error in Eclipse : Can not find the tag library descriptor for "http://java.sun.com/jsf/html"

Solution :

Add the following for having the jar in Eclipse classpath :

<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-impl</artifactId>
  <version>2.0.0-Beta2</version>
</dependency>

Friday, July 1, 2011

SAXException: The content of element type "web-app" must match ...


Problem


I deploy a war in JBoss 6.0.0 ( idem JBoss 5.1), I have the following error :

Caused by: org.xml.sax.SAXException: The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)". @ vfs:///opt/jboss/jboss-6.0.0.Final/server/dr_jbossweb-standalone/deploy/getting-spring.war/WEB-INF/web.xml[53,11]

I check my web.xml and there is nothing abnormal :

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:META-INF/properties/log4j.properties</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

  <!--All spring configuration files need to be loaded in context. Although we have single file but
  with the growing configuration stuff we need to break down configuration files too-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/integration-*.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <servlet>
    <!--Spring's front controller or dispatcher which will be responsible to handle every web request
    and dispatch it to a specific web controller-->
    <servlet-name>integration</servlet-name>
    <display-name>integration</display-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/integration-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!--Let every request be handled by Spring's Dispatcher servlet and it'll decide which web controller to call -->
  <!--based on @RequestMapping-->
  <servlet-mapping>
    <servlet-name>integration</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>
      index.jsp
    </welcome-file>
  </welcome-file-list>
</web-app>

So where is the error ?


Solution

The solution is simple but a little strange :
You have to put :
  <!--All spring configuration files need to be loaded in context. Although we have single file but
  with the growing configuration stuff we need to break down configuration files too-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/integration-*.xml</param-value>
  </context-param>

just before :

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

Cela donne le web.xml suivant :

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:META-INF/properties/log4j.properties</param-value>
  </context-param>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/integration-*.xml</param-value>
  </context-param>  
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <servlet>
    <!--Spring's front controller or dispatcher which will be responsible to handle every web request
    and dispatch it to a specific web controller-->
    <servlet-name>integration</servlet-name>
    <display-name>integration</display-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/integration-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!--Let every request be handled by Spring's Dispatcher servlet and it'll decide which web controller to call -->
  <!--based on @RequestMapping-->
  <servlet-mapping>
    <servlet-name>integration</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>
      index.jsp
    </welcome-file>
  </welcome-file-list>  
</web-app>

Wednesday, June 29, 2011

Can not find the tag library descriptor for "http://richfaces.org/a4j"


Problem :

My jsp contains the following line:

<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>


And Eclipse show the following error : Can not find the tag library descriptor for "http://richfaces.org/a4j"

Solution :

I add these dependencies for having jars in Eclipse Classpath :

<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl</artifactId>
<version>3.3.0.GA</version>
</dependency>
<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl-jsf2</artifactId>
<version>3.3.3.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-ui</artifactId>
<version>3.3.3.Final</version>
</dependency>

Tuesday, June 28, 2011

no declaration can be found for element 'aop:aspectj-autoproxy'

Problem :

Caused by: org.xml.sax.SAXParseException; lineNumber: 15; columnNumber: 28; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:aspectj-autoproxy'.

Solution :


There is a problem with xsd and schema location.In web.xml, I checked xsi:schemaLocation and there is no spring-aop-3.0.xsd.So I modify the web.xml file like that :

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

Monday, June 27, 2011

java.lang.ClassNotFoundException: org.aspectj.util.PartialOrder$PartialComparable

Problem :

When I deploy a war in JBoss 6.0.0, I've the following error :

java.lang.ClassNotFoundException: org.aspectj.util.PartialOrder$PartialComparable


Solution :

It lacks the aspectjweaver Maven dependency :

  <dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.6</version>
</dependency>

Friday, June 24, 2011

How adding log4j in or application Spring3 Maven JBoss6 ?

For adding log4j with Maven, the first things that you want to do is :
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.15</version>
</dependency>

You can't because of licensing issue of some fonctionnality in log4j.
I've found the explanation on http://unitstep.net/blog/2009/05/18/resolving-log4j-1215-dependency-problems-in-maven-using-exclusions/ :

If you’re using Maven to manage your project’s build and dependencies, you may have encountered some problems when trying to include the latest version of log4j as a dependency.
 Specifically, log4j 1.2.15 depends on some artifacts that are not available in the central Maven repository due to licensing issues, and thus when you try to build a project that depends on this version of log4j,
 you may not be able to download the artifacts and your build will fail.

So you have to do the following :
   <dependency>
     <groupId>log4j</groupId>
     <artifactId>log4j</artifactId>
     <version>1.2.15</version>
     <exclusions>
       <exclusion>
         <groupId>javax.mail</groupId>
         <artifactId>mail</artifactId>
       </exclusion>
       <exclusion>
         <groupId>javax.jms</groupId>
         <artifactId>jms</artifactId>
       </exclusion>
       <exclusion>
         <groupId>com.sun.jdmk</groupId>
         <artifactId>jmxtools</artifactId>
       </exclusion>
       <exclusion>
         <groupId>com.sun.jmx</groupId>
         <artifactId>jmxri</artifactId>
       </exclusion>
     </exclusions>
   </dependency>


I've add log4j dependency on the trunk of my tutorial google project with Spring Maven et JBoss 6.0.0 : http://code.google.com/p/lin-mon-webapp/



references :
http://unitstep.net/blog/2009/05/18/resolving-log4j-1215-dependency-problems-in-maven-using-exclusions/

Thursday, June 23, 2011

Maven Spring3 JBoss 6 Hibernate example

I'm proud to announce the first version of the lin-mon-webapp project with Spring 3 Hibernate Maven on JBoss 6.The source code and the war is avalaible on Google project : http://code.google.com/p/lin-mon-webapp/To success, I get help from this blog : http://www.nabeelalimemon.com/blog/2010/05/spring-3-integrated-with-hibernate-part-a/ (thanks :-)))

To build and deploy the application you need the following :

-> Maven 2
-> JBoss 6 ( In jbossweb-standalone/lib/ vous devez mettre les jars suivants :  jstl-1.1.2.jar et standard-1.1.2.jar )
-> Mysql and to create a database with a table User :

create database integration;
GRANT ALL ON integration.* TO 'integration'@'localhost' IDENTIFIED BY 'integration';
flush privileges;
create table USER (   
user_id int(11) primary key,   
first_name varchar(30),   
last_name varchar(30),   
email varchar(30) );
insert into USER values (1, 'titi', 'toto', 'mail@gmail.com');

Then you can show the total number of user and the user list by accessing  at the following page : http://localhost:8080/monitor/users

In the next section, I will show you the most important project files.



Here is the Maven pom.xml :

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.dr.linmon</groupId>
<artifactId>linmon</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Monitor app</name>
<repositories>
<repository>
  <id>JBoss Repo</id>
  <url>http://repository.jboss.com/maven2</url>
</repository>
</repositories>
<dependencies>
  <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${org.springframework.version}</version>
   </dependency>
   <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${org.springframework.version}</version>
   </dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aop</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context-support</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-tx</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>${org.springframework.version}</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-test</artifactId>
  <version>${org.springframework.version}</version>
</dependency>    
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>  
<dependency>
    <groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
     <groupId>junit</groupId>
     <artifactId>junit</artifactId>
     <version>4.5</version>
     <scope>runtime</scope>
</dependency>



        <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.9</version>
        </dependency>


   <dependency>
     <groupId>log4j</groupId>
     <artifactId>log4j</artifactId>
     <version>1.2.15</version>
     <exclusions>
       <exclusion>
         <groupId>javax.mail</groupId>
         <artifactId>mail</artifactId>
       </exclusion>
       <exclusion>
         <groupId>javax.jms</groupId>
         <artifactId>jms</artifactId>
       </exclusion>
       <exclusion>
         <groupId>com.sun.jdmk</groupId>
         <artifactId>jmxtools</artifactId>
       </exclusion>
       <exclusion>
         <groupId>com.sun.jmx</groupId>
         <artifactId>jmxri</artifactId>
       </exclusion>
     </exclusions>
   </dependency>
   <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-validator</artifactId>
     <version>4.0.2.GA</version>
     <exclusions>
  <exclusion>
    <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
   </exclusion>      
     </exclusions>
   </dependency>
   <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-annotations</artifactId>
     <version>3.4.0.GA</version>
     <exclusions>
       <!-- Exclude Commons Logging in favor of SLF4j -->
       <exclusion>
         <groupId>org.apache.commons</groupId>
         <artifactId>com.springsource.org.apache.commons.logging</artifactId>
       </exclusion>
   <exclusion>
     <groupId>xml-apis</groupId>
     <artifactId>xml-apis</artifactId>
   </exclusion>
   <exclusion>
     <groupId>org.slf4j</groupId>
     <artifactId>slf4j-api</artifactId>
   </exclusion>            
     </exclusions>
   </dependency>
   <dependency>
      <groupId>javax.persistence</groupId>
      <artifactId>persistence-api</artifactId>
      <version>1.0</version>
    </dependency>
   <dependency>
     <groupId>commons-dbcp</groupId>
     <artifactId>commons-dbcp</artifactId>
     <version>1.2.2</version>
   </dependency>
   <dependency>
     <groupId>org.aspectj</groupId>
     <artifactId>aspectjrt</artifactId>
     <version>${aspectj.version}</version>
   </dependency>
  <dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>


<build>
<finalName>monitor</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.4</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
  
<properties>
    <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
    <aspectj.version>1.6.6</aspectj.version>    
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

First the web.xml in whicn we create the servlet monitor :

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Maven Spring MVC 3 with JBOSS 6 </display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>     
  
  <!-- Front servlet.  -->
  <servlet>
<servlet-name>monitor</servlet-name>
<display-name>monitor</display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/monitor-servlet.xml</param-value>
    </init-param>
<load-on-startup>1</load-on-startup>
  </servlet>
 
<!-- Every request on / will be treat by monitor servlet. -->
  <servlet-mapping>
<servlet-name>monitor</servlet-name>
<url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

Then there is the monitor servlet which define the controller, view relover ... and also where to search controller methods:

monitor-servlet.xml :

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName">
<!-- Every contoller is automaticaly detect due to annotation @Controller.
    We define here in wich package the post processor have to search controller annotation -->
  <context:component-scan base-package="fr.dr.monitor.controller"/>  


<context:annotation-config/>


<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

<bean 
class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
</beans>


The controller class contains this method :

@RequestMapping(value = "users", method = RequestMethod.GET)
public ModelAndView getUsers() {
  List<User> users = userDAO.getUsers();
  ModelAndView modelAndView = new ModelAndView("users");
  modelAndView.addObject("users", users);
  return modelAndView;
}

To do that the controller call UserDAO methods and Hibernate will retreive data in User table.
Here is the spring beans file that create Hibernate Session and datasource :

spring.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">


 <!--  <context:component-scan base-package="com.springhibernate.integration.aspects" />-->

 <!--Enables the use of @AspectJ style of aspects' declarations. AspectJ run-time isn't necessarily involved-->
 <aop:aspectj-autoproxy/>

 <!--Platform Transaction Manager declared as "transactionManager" will be used.-->
 <!--"aspectj" mode enables load-time/compile-time weaving of transactional methods, which enables
  those methods to be intercepted even when called internally.
  (Unlike Spring generated proxies which will only be intercepted when called from outside)--> 
 <tx:annotation-driven transaction-manager="transactionManager"/>

<!--
Activates various annotations to be detected in bean classes: Spring's
@Required and @Autowired, as well as JSR 250's @PostConstruct,
@PreDestroy and @Resource (if available) and JPA's @PersistenceContext
and @PersistenceUnit (if available).
-->
<context:annotation-config/>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 <property name="dataSource" ref="dataSource"/>
 <property name="hibernateProperties">
   <props>
     <prop key="dialect">org.hibernate.dialect.MySQL5Dialect</prop>
     <prop key="show_sql">true</prop>
   </props>
 </property>
 <property name="mappingResources">
   <list>
     <value>mappings/user.hbm.xml</value>
   </list>
 </property>
</bean>

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

<context:property-placeholder location="classpath*:/META-INF/properties/*.properties"/>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
 <property name="driverClassName" value="${database.driverClassName}"/>
 <property name="url" value="${database.url}"/>
 <property name="username" value="${database.username}"/>
 <property name="password" value="${database.password}"/>
</bean>



  <!--repository init area-->
  <bean id="repository.users" class="fr.dr.monitor.repository.UserDAO"
        autowire="constructor"/>
</beans>

The session factory will be inject to UserDAO to query on USER table :

UserDAO.java


@Repository
@Transactional
public class UserDAO implements IUser {


private SessionFactory sessionFactory;


@Autowired
public UserDAO(SessionFactory sessionFact) {
this.sessionFactory = sessionFact;
}


@Transactional
public User getUser(Long id) {
return (User) sessionFactory.getCurrentSession().get(User.class, id);
}


@SuppressWarnings("unchecked")
@Transactional
public List<User> getUsers() {
return sessionFactory.getCurrentSession().createQuery("from User user").list();
}


@Transactional
public void addUser(User user) {
sessionFactory.getCurrentSession().save(user);
}
}

All the code is available on google project with Apache License V2 : http://code.google.com/p/lin-mon-webapp/