0
votes

SOLVED: I converted the application from spring-boot to standard spring mvc and it now works. Thanks for everyone who tried to help. Still not sure what the issue was but I've got it working now.


I'm trying to deploy webapps to tomcat 7. The apps are built using spring-boot and packaged using maven.

I am placing the wars in the webapps folder and it is being deployed successfully:

Jul 31, 2015 1:22:05 PM org.apache.catalina.startup.HostConfigdeployWAR

INFO: Deploying web application archive /var/lib/tomcat7/webapps/application.war

Jul 31, 2015 1:22:09 PM org.apache.catalina.startup.HostConfig deployWAR

INFO: Deploying web application archive /var/lib/tomcat7/webapps/Application.war

Jul 31, 2015 1:22:10 PM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT

Jul 31, 2015 1:22:11 PM org.apache.coyote.AbstractProtocol start

INFO: Starting ProtocolHandler ["http-bio-8080"]

Jul 31, 2015 1:22:11 PM org.apache.catalina.startup.Catalina start

INFO: Server startup in 6796 ms

However, when I try to access them through the browser I get a 404 message (The requested resource is not available.). I can see the ROOT index and get to the manager app, where they are correctly identified as Spring MVC and I am told they are deployed and running. Clicking on the link within the manager gives me the same result. catalina.out isn't telling me anything. It doesn't give me anymore information after the server startup message.

EDIT WITH MORE INFO This is the web.xml for the application

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

    <display-name>Spring MVC Application</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

Controller handling index requests:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
/**
 * Default Controller.
 */
class HelloController {
    /**
     * Implementation of logging interface in SL4J.
     */
    private static final Logger LOGGER = LoggerFactory.getLogger
            (HelloController.class);

    /**
     * Constructs a new Hello Controller
     */
    public HelloController() {
        LOGGER.trace("Created hello controller");
    }

    /**
     * Prints the message on the screen
     * @param model the model to add the message too
     * @return a String
     */
    @RequestMapping(method = RequestMethod.GET)
    public String printWelcome(final ModelMap model) {
        model.addAttribute("message", "Hello world!");
        return "hello";
    }
}

The urls I am trying to access are http://localhost:8080/application/ and http://localhost:8080/Application/

I have also tried it in Tomcat 8 and get the same issue. I tried copying the ROOT folder and renaming the copy to application and can access that fine. Seems to be something with the war?

2
Post the requested uri and the uri which is mapped on the application. (web.xml, annotation or something else)Zelldon
Updated with more informationSelketDaly
try to add the * in the url pattern after the '/'Zelldon
Modified web.xml to use <url-pattern>/*</url-pattern>. Still the same issueSelketDaly
also the class should be public ! Add the 'public' keyword before the HelloControllerZelldon

2 Answers

0
votes

It seems like the application is deployed under ROOT context. This will be the case if the context path is empty string. for ex:

<Context path="" docBase="${catalina.home}/webapps/application.war" >

So your application should be available on "http:localhost:8080/". If you want the application to be available on "http:localhost:8080/applicaiton" then there are 2 ways:

  1. If you are defining "<Context>" element in server.xml, then define it as :<Context path="/application" docBase="${catalina.home}/webapps/application.war">

  2. As per below documentation, you need to add a context xml by name "application.xml" in your host directory of the server.For ex - "{catalina.base}/conf/Catalina/localhost/application.xml" https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming

0
votes
<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">

Try using the latest web app version and make sure to check the spellings very carefully or missing tags.