Why is the HTTP Status 404 error occurring in my Jboss Tomcat 7 + Spring MVC application?

Asked

Viewed 1,033 times

1

I’m running some tests on the MVC JBoss 7 + Spring, and locally it runs, but when I put it in the cloud, it generates the error HTTP Status 404.

Organization of Briefcase:

/pswebproj/src/main/java/pswebproj/control/Hellocontroller.java

package pswebproj.control;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/hello")
// URL Controlador 
// - http://localhost:8080/pswebproj/spring/hello
public class HelloController
{
    @RequestMapping("/simple") // .../pswebproj/spring/hello/simple
    public ModelAndView helloRequest()
    {
        String model = "Message from helloRequest(), UAU!";

        ModelAndView mv = new ModelAndView("/hellospring.jsp");
        mv.addObject("msg", model);
        return mv;
    }

    @RequestMapping("/param") // .../pswebproj/spring/hello/param?prm=sbrubbles
    public ModelAndView helloRequestParam(@RequestParam String prm)
    {
        String model = "Message from helloRequestParam() "+prm;

        ModelAndView mv = new ModelAndView("/hellospring.jsp");
        mv.addObject("msg", model);
        return mv;
    }

    @RequestMapping(value="/pathvar/{var}") 
    //.../pswebproj/spring/hello/pathvar/sbrubbles
    public ModelAndView helloRequestPath(@PathVariable String var)
    {
        String model = "Message from helloRequestPath() "+var;

        ModelAndView mv = new ModelAndView("/hellospring.jsp");
        mv.addObject("msg",model);
        return mv;
    }   
}

/pswebproj/pom.xml

<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>pswebproj</groupId>
    <artifactId>pswebproj</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>pswebproj</name>
    <repositories>
        <repository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.2-1003-jdbc4</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>     
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <!-- SERVLET -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>               
        <!-- // SERVLET -->
        <!-- SPRING -->        
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.7.RELEASE</version>
        </dependency>       
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.3.7.RELEASE</version>
        </dependency>      
        <!-- // SPRING -->  
    </dependencies>
    <profiles>
        <profile>
            <!-- When built in OpenShift the 'openshift' profile will be used when 
                invoking mvn. -->
            <!-- Use this profile for any OpenShift specific customization your app 
                will need. -->
            <!-- By default that is to put the resulting archive into the 'webapps' 
                folder. -->
            <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
            <id>openshift</id>
            <build>
                <finalName>pswebproj</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.1.1</version>
                        <configuration>
                            <outputDirectory>webapps</outputDirectory>
                            <warName>ROOT</warName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <build>
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            org.apache.maven.plugins
                                        </groupId>
                                        <artifactId>
                                            maven-compiler-plugin
                                        </artifactId>
                                        <versionRange>
                                            [3.1,)
                                        </versionRange>
                                        <goals>
                                            <goal>testCompile</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

/pswebproj/src/main/webapp/WEB-INF/web.xml

<web-app version="3.0"
         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_3_0.xsd"
         metadata-complete="false">
  <display-name>PsWeb Example Project</display-name>

  <servlet>
        <servlet-name>springweb</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>  
    <servlet-mapping>
        <servlet-name>springweb</servlet-name>
        <url-pattern>/spring/*</url-pattern>
    </servlet-mapping>  
</web-app>

/pswebproj/src/main/webapp/WEB-INF/springweb-Servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    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.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Pacotes a serem escaneados -->
    <context:component-scan base-package="pswebproj.control" />

    <!--  Define quais anotações estão habilitadas -->
    <mvc:annotation-driven />

</beans>

I’m using JDK 1.7.0_80 + Tomcat 7 . I can also run the site with the URL: http://localhost:8080/pswebproj/spring/hello/simple

As a way out I get :

Java Puro: Message from helloRequest(), UAU!
JSTL: Message from helloRequest(), UAU!
EL: Message from helloRequest(), UAU!

However if I run in the cloud with the URL: http://pswebproj-drinith.rhcloud.com/spring/hello/simple , i receive as response the HTTP Status 404.

  • I think you forgot to pass the context-root of the application, try calling using this url: http://pswebproj-drinith.rhcloud.com/pswebprojs/spring/hello/simple

  • Sorry if that’s not the case, but if localhost works like this: http://localhost:8080/pswebproj/spring/hello/simple Your url should be: http://pswebproj-drinith.rhcloud.com/pswebproj/spring/hello/simple

  • Exactly my friend, but it doesn’t work, and I’m trying to use in the environment the same things that jboss of this version uses.

1 answer

0


Guys I don’t know what could have happened, redoing the tests to show my teacher, he asked to see the console output from the server and looking did not even see an error output when I went to test with the normal url again simply ran, I do not remember changing anything.

Thank you to the forum anyway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.