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/ 

Tuesday, June 21, 2011

java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory

Problem :

Lors du déploiement d'un war dans JBoss 6.0.0, j'ai l'erreur suivante :

21:27:49,119 INFO  [STDOUT] Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader
 (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder,
 have different Class objects for the type org/slf4j/ILoggerFactory used in the signature


Solution :

There is conflict between libraries in the war and in JBoss.To resolve this problem, you have to exclude
sl4j.For example Hibernate.

   <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>
       <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>


Remarque : Un bon moyen de voir toutes les dépendances Maven ramenées dans notre war, c'est de regarder dans Eclipse la vue Dependency Hierachy.

Monday, June 20, 2011

Tutorial for Spring 3, JBoss 6 with Maven on Google project

I've just create a google project for an application with Spring 3 and Maven on JBoss 6.
Today, the application is a very simple MVC application without persistence. The goal of this project is to create several "tutorial" tags ( one for making a Spring MVC, one for adding hibernate ...).

http://code.google.com/p/lin-mon-webapp/

java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config

Problem :

When I open a jsp page in the browser, I have the following error :

20:16:32,243 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/getting-spring].[integration]] "Servlet.service()" pour la servlet integration a généré une exception: java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config from BaseClassLoader@74c252{vfs:///opt/jboss/jboss-6.0.0.Final/server/dr_jbossweb-standalone/deploy/getting-spring.war}
        at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480) [jboss-classloader.jar:2.2.0.GA]


I looked in my pom.xml and I have correct Maven dependencies:



    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <scope>provided</scope>
      <version>1.1.2</version>
    </dependency>
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <scope>provided</scope>
      <version>1.1.2</version>
    </dependency>



So it's Ok.Moreover I checked in my war and there are these dependencies but there is always the error.


Solution


I add jstl-1.1.2.jar in the directory lib (in JBoss 6 for example you can add in  jbossweb-standalone/lib)


Note : You can find this jar on Maven repositories : here

Sunday, June 19, 2011

Maven Spring MVC 3 with JBOSS 6 example

Goals :

The main goal of this example is to show a maven configuration for Spring MVC3 and JBoss 3 (without database).
The source code is available on Google code : http://code.google.com/p/lin-mon-webapp/ (cf tutorial1 in wiki)


Project :



Maven :

We use the Spring's version 3.0.5 because older version doesn't work with JBOSS 6 (there is a bug with VFS).



Here is my pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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.monitor</groupId>
    <artifactId>monitor</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Monitor app</name>
    
    <dependencies>
      <dependency>
            <groupId>org.springframework</groupId>
     <artifactId>spring-beans</artifactId>
     <version>${org.springframework.version}</version>
      </dependency>

      <dependency>
    <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
    <version>${org.springframework.version}</version>
      </dependency>
      <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</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>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</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>
<!-- Permet de créer un projet eclipse avec Maven -->
<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>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
</project>


src/main/resources/spring.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:p="http://www.springframework.org/schema/p" 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-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/aop http://www.springframework.org/schema/tx/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName">
<!--
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/>
</beans>



/WEB-INF/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>
   <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>     
  
   <!-- declare la servlet frontale centrale  -->
   <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>
  
   <servlet-mapping>
<servlet-name>monitor</servlet-name>
<url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>


/WEB-INF/monitor-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Fichier de conf du contexte d'application pour spring (fichier nommé spring-mvc-webapp-servlet.xml selon la convention. -->
<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">
<!-- - Tous les controlleurs sont automatiquement détectés grâce à l'annotation @Controller.
- On définit ici dans quel package le post processor doit chercher ces beans annotés. -->
   <context:component-scan base-package="fr.dr.monitor.controller"/>   
<!-- 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 & @PersistenceUnit.
-->
<context:annotation-config/>
<!--
- Les controlleurs de cette application fournissent une annotation @RequestMapping 
- Qui peuvent être déclaré de deux manière différentes:
-  Au niveau de la classe : 
-      par exemple @RequestMapping("/addVisit.html")
-      Pour ce type de controlleurs on peut annoter les méthodes pour une requete Post ou Get,
- Au niveau de chaque méthodes, différents exemples  seront fournis.  
-->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<!--
Ceci est le view resolver, il permet de définir la technologie de vue utilisée et comment
sélectionner une vue. Ici on prendra la solution la plus simple elle permet de mapper 
le nom de la vue retournée avec la sélection d'une jsp. Ex. si le nom de la vue retournée est "hello" alors on utilisera le fichier
WEB-INF/jsp/hello.jsp pour constuire la vue. 
-->
<bean 
 class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
 p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
</beans>


/WEB-INF/jsp/index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored ="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>

Bonjour ${name},

</body>
</html>


fr.dr.monitor.controller.MainController

package fr.dr.monitor.controller;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
public class MainController  {

 final Logger logger=Logger.getLogger(getClass().getName());

 /**
    * Handler de la méthode Get pour l'URL /helloSpringMVC.html. 
    * 
    * @param name le nom que l'on doit afficher dans la vue.
    * @param model une map de toutes les données qui seront utilisables dans la vue 
    * @return le nom de la vue qu'il faudra utiliser.
    */
  @RequestMapping(value="/")
  public  String toIndex(
    @RequestParam(value="name",required=false) String name, 
    ModelMap model) 
  {
logger.info(">toIndex");
    model.addAttribute("name",name);
    logger.info(">add attribute name " + name);
    
    // on utilisera donc le fichier /WEB-INF/jsp/index.jsp
    //au regard de la stratégie de résolution des vues 
    //utilisée dans cette application.
    return "index";
  }

}

Réferences :