Bonjour,

J'essaie de configurer mon projet SpringMVC grâce à des classes java ( donc pas de fichiers xml, web.xml, etc). Quand j’exécute mon projet le serveur ne signale aucune erreur mais cela ne marche pas. je cherche le chic sans trouver. merci de votre aide.
Voici mes différentes classes.

Ma classe de configuration
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
package template.Configuration;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
 
@Configuration
@ComponentScan( { "template.*" } )
public class ApplicationConfig {
 
    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass( JstlView.class );
        viewResolver.setPrefix( "/WEB-INF/views/" );
        viewResolver.setSuffix( ".jsp" );
        return viewResolver;
    }
 
}
Ma classe d'initialisation de spring mvc
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
package template.Configuration;
 
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
 
public class SpringMVCWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
 
    @Override
    protected Class<?>[] getRootConfigClasses() {
 
        return new Class[] { ApplicationConfig.class };
    }
 
    @Override
    protected Class<?>[] getServletConfigClasses() {
 
        return null;
    }
 
    @Override
    protected String[] getServletMappings() {
 
        return new String[] { "/" };
    }
 
}
Enfin mon controler
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
 
@Controller
public class WebController {
 
    @RequestMapping( value = { "/", "/index**" }, method = RequestMethod.GET )
    public ModelAndView index() {
        ModelAndView model = new ModelAndView();
        model.addObject( "message", "template ok!!" );
        model.setViewName( "index" );
        return model;
 
    }
 
}
Le rendu du serveur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
juil. 19, 2016 1:39:24 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVERTISSEMENT: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:projetWebTemplateJavaConfigAnnotation' did not find a matching property.
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server version:        Apache Tomcat/8.0.28
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server built:          Oct 7 2015 18:25:21 UTC
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server number:         8.0.28.0
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: OS Name:               Linux
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: OS Version:            4.2.0-30-generic
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Architecture:          amd64
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Java Home:             /usr/lib/jvm/java-7-openjdk-amd64/jre
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: JVM Version:           1.7.0_101-b00
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: JVM Vendor:            Oracle Corporation
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: CATALINA_BASE:         /local/home/fnjiokou/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: CATALINA_HOME:         /local/home/fnjiokou/workspace/apache-tomcat-8.0.28
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dcatalina.base=/local/home/fnjiokou/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dcatalina.home=/local/home/fnjiokou/workspace/apache-tomcat-8.0.28
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dwtp.deploy=/local/home/fnjiokou/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Djava.endorsed.dirs=/local/home/fnjiokou/workspace/apache-tomcat-8.0.28/endorsed
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dfile.encoding=UTF-8
juil. 19, 2016 1:39:24 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFOS: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib32:/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
juil. 19, 2016 1:39:24 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["http-nio-8081"]
juil. 19, 2016 1:39:24 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFOS: Using a shared selector for servlet write/read
juil. 19, 2016 1:39:24 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["ajp-nio-8009"]
juil. 19, 2016 1:39:24 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFOS: Using a shared selector for servlet write/read
juil. 19, 2016 1:39:24 PM org.apache.catalina.startup.Catalina load
INFOS: Initialization processed in 899 ms
juil. 19, 2016 1:39:24 PM org.apache.catalina.core.StandardService startInternal
INFOS: Démarrage du service Catalina
juil. 19, 2016 1:39:24 PM org.apache.catalina.core.StandardEngine startInternal
INFOS: Starting Servlet Engine: Apache Tomcat/8.0.28
juil. 19, 2016 1:39:25 PM org.apache.jasper.servlet.TldScanner scanJars
INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
juil. 19, 2016 1:39:26 PM org.apache.jasper.servlet.TldScanner scanJars
INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
juil. 19, 2016 1:39:26 PM org.apache.catalina.core.ApplicationContext log
INFOS: 1 Spring WebApplicationInitializers detected on classpath
juil. 19, 2016 1:39:27 PM org.apache.catalina.core.ApplicationContext log
INFOS: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
juil. 19, 2016 1:39:27 PM org.apache.catalina.core.ApplicationContext log
INFOS: Initializing Spring FrameworkServlet 'dispatcher'
juil. 19, 2016 1:39:28 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-nio-8081"]
juil. 19, 2016 1:39:28 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["ajp-nio-8009"]
juil. 19, 2016 1:39:28 PM org.apache.catalina.startup.Catalina start
INFOS: Server startup in 3543 ms