java - Spring Maven + IntelliJ and 404 -


so, today decided try out intellij idea.

after setting tried make simple spring webmvc project.

and spring application, i'm @ point don't have errors or warnings 404 page when run project...

tomcat 9 runs without warnings or errors , java seem have no problems. running open browser way way common 404 - resource not found error.

springtest.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/xsd/maven-4.0.0.xsd">     <modelversion>4.0.0</modelversion>      <groupid>com.clomez</groupid>     <artifactid>springtest</artifactid>     <version>1.0-snapshot</version>      <packaging>war</packaging>      <dependencies>         <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-webmvc</artifactid>             <version>4.3.6.release</version>         </dependency>         <dependency>             <groupid>javax</groupid>             <artifactid>javaee-web-api</artifactid>             <version>7.0</version>             <scope>provided</scope>         </dependency>     </dependencies> </project> 

homecontroller

package com.clomez.controller;  import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.requestmapping;  /**  * created clomez-admin on 14.4.2017.  */  @controller public class homecontroller {      @requestmapping(value = "/")     public string home(){          return "home";     } } 

webinit.class

package com.clomez.config;  import org.springframework.context.annotation.configuration; import org.springframework.web.servlet.support.abstractannotationconfigdispatcherservletinitializer;  /**  * created clomez-admin on 14.4.2017.  */  @configuration public class webinit  extends abstractannotationconfigdispatcherservletinitializer{     @override     protected class<?>[] getrootconfigclasses() {         return new class[]{rootconfig.class};     }     @override     protected class<?>[] getservletconfigclasses() {         return new class[]{webconfig.class};     }     @override     protected string[] getservletmappings() {         return new string[]{"/"};     } } 

rootconf.class

package com.clomez.config;  import org.springframework.context.annotation.configuration;  /**  * created clomez-admin on 14.4.2017.  */  @configuration public class rootconfig { } 

webconfig.class

package com.clomez.config;  import org.springframework.context.annotation.bean; import org.springframework.context.annotation.componentscan; import org.springframework.context.annotation.configuration; import org.springframework.web.servlet.config.annotation.enablewebmvc; import org.springframework.web.servlet.config.annotation.webmvcconfigureradapter; import org.springframework.web.servlet.view.internalresourceviewresolver;  /**  * created clomez-admin on 14.4.2017.  */  @configuration @enablewebmvc @componentscan("com.clomez") public class webconfig extends webmvcconfigureradapter{     @bean     public internalresourceviewresolver resolver(){          internalresourceviewresolver resolver = new internalresourceviewresolver();         resolver.setprefix("/");         resolver.setsuffix(".jsp");         return resolver;     } } 

please can me this? after 2 months feel getting cancer spring framework thing, don't have choice if want complete degree.

tomcat runs smoothly, there aren't errors or warnings in editor, , brings browser 404 - home.jsp not found.

i've got code running on wildfly 10 , after dropped home.jsp /src/main/webapp/ directory served content.

09:55:10,036 info  [io.undertow.servlet] (serverservice thread pool -- 69) 1 spring webapplicationinitializers detected on classpath 09:55:10,105 info  [javax.enterprise.resource.webcontainer.jsf.config] (serverservice thread pool -- 69) initializing mojarra 2.2.13.sp1 20160303-1204 context '/springtest-0.0.1-snapshot' 09:55:10,808 info  [io.undertow.servlet] (serverservice thread pool -- 69) initializing spring root webapplicationcontext 09:55:10,809 info  [org.springframework.web.context.contextloader] (serverservice thread pool -- 69) root webapplicationcontext: initialization started 09:55:10,818 info  [org.springframework.web.context.support.annotationconfigwebapplicationcontext] (serverservice thread pool -- 69) refreshing root webapplicationcontext: startup date [fri apr 14 09:55:10 edt 2017]; root of context hierarchy 09:55:10,852 info  [org.springframework.web.context.support.annotationconfigwebapplicationcontext] (serverservice thread pool -- 69) registering annotated classes: [class com.clomez.config.rootconfig] 09:55:10,962 info  [org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor] (serverservice thread pool -- 69) jsr-330 'javax.inject.inject' annotation found , supported autowiring 09:55:11,018 info  [org.springframework.web.context.contextloader] (serverservice thread pool -- 69) root webapplicationcontext: initialization completed in 209 ms 09:55:11,027 info  [io.undertow.servlet] (serverservice thread pool -- 69) initializing spring frameworkservlet 'dispatcher' 09:55:11,027 info  [org.springframework.web.servlet.dispatcherservlet] (serverservice thread pool -- 69) frameworkservlet 'dispatcher': initialization started 09:55:11,030 info  [org.springframework.web.context.support.annotationconfigwebapplicationcontext] (serverservice thread pool -- 69) refreshing webapplicationcontext namespace 'dispatcher-servlet': startup date [fri apr 14 09:55:11 edt 2017]; parent: root webapplicationcontext 09:55:11,030 info  [org.springframework.web.context.support.annotationconfigwebapplicationcontext] (serverservice thread pool -- 69) registering annotated classes: [class com.clomez.config.webconfig] 09:55:11,116 info  [org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor] (serverservice thread pool -- 69) jsr-330 'javax.inject.inject' annotation found , supported autowiring 09:55:11,270 info  [org.springframework.web.servlet.mvc.method.annotation.requestmappinghandlermapping] (serverservice thread pool -- 69) mapped "{[/]}" onto public java.lang.string com.clomez.controller.homecontroller.home() 09:55:11,481 info  [org.hibernate.validator.internal.util.version] (serverservice thread pool -- 69) hv000001: hibernate validator 5.2.4.final 09:55:11,539 info  [org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter] (serverservice thread pool -- 69) looking @controlleradvice: webapplicationcontext namespace 'dispatcher-servlet': startup date [fri apr 14 09:55:11 edt 2017]; parent: root webapplicationcontext 09:55:11,615 info  [org.springframework.web.servlet.dispatcherservlet] (serverservice thread pool -- 69) frameworkservlet 'dispatcher': initialization completed in 588 ms 09:55:11,616 info  [org.wildfly.extension.undertow] (serverservice thread pool -- 69) wflyut0021: registered web context: /springtest-0.0.1-snapshot 09:55:11,635 info  [org.jboss.as.server] (serverservice thread pool -- 34) wflysrv0010: deployed "springtest-0.0.1-snapshot.war" (runtime-name : "springtest-0.0.1-snapshot.war") 

when return "home" in homecontroller, internalresourceviewresolver set in webconfig used resolve jsps against internals or war (where default base of war file had /src/main/webapp added maven).

edit:

and confirm you, downloaded tomcat 9.0.0.m19 , receiving 404 when request http://localhost:8080/springtest-0.0.1-snapshot/. i'll give 8 quick whirl.

edit 2:

tomcat 8.5.13 returns 404 well. . . . both 8.5 , 9 support servlet 3 spec, i'm guessing there's wrinkle in there somewhere when collides these newer spring features. found spring java config: tomcat deploy without web.xml , http://docs.spring.io/autorepo/docs/spring-framework/4.3.x/javadoc-api/org/springframework/web/webapplicationinitializer.html notes that:

mapping '/' under tomcat

apache tomcat maps internal defaultservlet "/", , on tomcat versions <= 7.0.14, servlet mapping cannot overridden programmatically. 7.0.15 fixes issue. overriding "/" servlet mapping has been tested under glassfish 3.1.

i did try changing mapping / /home , tomcat still wasn't happy (wildfly was).

more edits come if find anything.

edit 3:

umm. well, i'm bit gobsmacked. tested tomcat 9, instead of requesting http://localhost:8080/springtest-0.0.1-snapshot/ try going http://localhost:8080/springtest/. home.jsp, above, code works!

edit 4 (sigh):

for completeness , perhaps because i'm using eclipse, had add 2 bits of maven build plugin configuration:

<build>     <plugins>         <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-compiler-plugin</artifactid>             <version>3.5.1</version>             <configuration>                 <source>1.8</source>                 <target>1.8</target>             </configuration>         </plugin>         <plugin>             <groupid>org.apache.maven.plugins</groupid>             <artifactid>maven-war-plugin</artifactid>             <version>3.0.0</version>             <configuration>                 <failonmissingwebxml>false</failonmissingwebxml>             </configuration>         </plugin>     </plugins> </build> 

i wouldn't expect these affect if haven't previously.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -