I get 404 error in my browser, after I start my tomcat :
I type in localhost:8080/mvc/hello or localhost:8080/mvc/hello.jsp
But if I type in localhost:8080, it is normal, can access:
In my springmvc-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!-- scan the package and the sub package -->
<context:component-scan base-package="com.ypd.springmvcdemo"/>
<!-- don't handle the static resource -->
<mvc:default-servlet-handler />
<!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven />
<!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
And in my MVCController.java:
#Controller
#RequestMapping("/mvc")
public class MVCController {
#RequestMapping("/hello")
public String hello() {
return "hello";
}
}
In my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
This is my page of hello.jsp:
(I am sorry about the springmvc-servlet.xml's position, I have locate it to under the resource library)
UPDATE - 1:
I am so sorry about it, there is a mistake when I post this snapshot, in my issue project, the web folder has no blue dot on it.See my answer I find the issue with it.
Update image:
So, where is the mistake?
EDIT
My hello.jsp:
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
Hello, world, jack loly!
</body>
</html>
EDIT
Logs looks like correct:
[2017-03-20 03:06:48,255] Artifact SpringMVCDemo:war exploded: Server is not connected. Deploy is not available.
Connected to the target VM, address: '127.0.0.1:51764', transport: 'socket'
20-Mar-2017 15:06:50.080 info [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/9.0.0.M17
20-Mar-2017 15:06:50.085 info [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jan 10 2017 20:59:20 UTC
20-Mar-2017 15:06:50.085 info [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 9.0.0.0
20-Mar-2017 15:06:50.085 info [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Mac OS X
20-Mar-2017 15:06:50.088 info [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.12.2
20-Mar-2017 15:06:50.089 info [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x86_64
20-Mar-2017 15:06:50.089 info [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre
20-Mar-2017 15:06:50.089 info [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_121-b13
20-Mar-2017 15:06:50.089 info [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
20-Mar-2017 15:06:50.089 info [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /Users/jack/Library/Caches/IntelliJIdea2016.3/tomcat/Tomcat_9_0_0_M17_SpringMVCDemo
20-Mar-2017 15:06:50.090 info [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /Users/jack/Library/Tomcat9
20-Mar-2017 15:06:50.091 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/Users/jack/Library/Caches/IntelliJIdea2016.3/tomcat/Tomcat_9_0_0_M17_SpringMVCDemo/conf/logging.properties
20-Mar-2017 15:06:50.091 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
20-Mar-2017 15:06:50.091 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:51764,suspend=y,server=n
20-Mar-2017 15:06:50.091 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
20-Mar-2017 15:06:50.092 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
20-Mar-2017 15:06:50.093 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
20-Mar-2017 15:06:50.093 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
20-Mar-2017 15:06:50.093 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
20-Mar-2017 15:06:50.093 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
20-Mar-2017 15:06:50.093 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
20-Mar-2017 15:06:50.093 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/Users/jack/Library/Caches/IntelliJIdea2016.3/tomcat/Tomcat_9_0_0_M17_SpringMVCDemo
20-Mar-2017 15:06:50.094 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/Users/jack/Library/Tomcat9
20-Mar-2017 15:06:50.094 info [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/Users/jack/Library/Tomcat9/temp
20-Mar-2017 15:06:50.094 info [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/jack/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
20-Mar-2017 15:06:50.527 info [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
20-Mar-2017 15:06:50.560 info [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
20-Mar-2017 15:06:50.563 info [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
20-Mar-2017 15:06:50.565 info [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
20-Mar-2017 15:06:50.581 info [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1455 ms
20-Mar-2017 15:06:50.709 info [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
20-Mar-2017 15:06:50.709 info [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.0.M17
20-Mar-2017 15:06:50.745 info [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8080]
20-Mar-2017 15:06:50.766 info [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009]
20-Mar-2017 15:06:50.769 info [main] org.apache.catalina.startup.Catalina.start Server startup in 187 ms
Connected to server
[2017-03-20 03:06:51,046] Artifact SpringMVCDemo:war exploded: Artifact is being deployed, please wait...
[2017-03-20 03:06:51,751] Artifact SpringMVCDemo:war exploded: Artifact is deployed successfully
[2017-03-20 03:06:51,751] Artifact SpringMVCDemo:war exploded: Deploy took 705 milliseconds
20-Mar-2017 15:07:00.750 info [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /Users/jack/Library/Tomcat9/webapps/manager
20-Mar-2017 15:07:00.802 info [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /Users/jack/Library/Tomcat9/webapps/manager has finished in 52 ms
EDIT
My tomcat deployment config:
EDIT -2
I think your tomcat deployment configuration is not all okay. your application context should be the context from where you are going to load your application and tell tomcat to dispatch all request within that context.
e.g. your Application Context: could be /helloApp. Now when you will start tomcat, your application would be loaded at localhost:8080/helloApp/. And this is your application root context. Now if you hit at localhost:8080/helloApp/mvc/hello, you are expected to see your content.
Put your springmvc-servlet.xml file in the WEB-INF and change lines of web.xml
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
To
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
There are couple of things to notice.
No project name specified in url
URL should be : http://localhost:8080/SpringMVCDemo/mvc/hello
Why are you mentioning two RequestMapping(mvc,hello) for only one page.You can remove #RequestMapping(value="/mvc") and keep #RequestMapping("/hello") on hello() method.
Update:
add load-on-startup in web.xml
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
At last, I find the issue I was lost. See my question -> UPDATE -1
No blue dot on it means Web Source Dictory is incorrect. See below image I find the issue.
So I delete the red directory, and then re-choose the web directory:
Then in my project, I can see the blue dot on web directory now:
And then I restart tomcat, I success:
Related
I'm new to Spring and trying MVC. I built simple demo app and run it on tomcat 9.0.41
It seems artifact is deploied correctly and problem seems to be in Controller mapping ... it simply can not find my jsp.
here is my project structure
here is web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>spring-mvc-demo</display-name>
<!-- <context-param>-->
<!-- <param-name>contextConfigLocation</param-name>-->
<!-- <param-value>/WEB-INF/applicationContext.xml</param-value>-->
<!-- </context-param>-->
<!-- <listener>-->
<!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>-->
<!-- </listener>-->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring-mvc-demo-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>spring-mvc-demo</display-name>
<!-- <context-param>-->
<!-- <param-name>contextConfigLocation</param-name>-->
<!-- <param-value>/WEB-INF/applicationContext.xml</param-value>-->
<!-- </context-param>-->
<!-- <listener>-->
<!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>-->
<!-- </listener>-->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
HomeController
package com.springmvcdemo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HomeController {
#RequestMapping("/")
public String showPage(){
return "main-menu";
}
}
and simple main-menu.jsp
<html>
<body>
<h2>
Spring Demo MVC - Home page
</h2>
</body>
</html>
here is server log
"C:\Program Files\Apache Software Foundation\Tomcat 9.0\bin\catalina.bat" run
[2021-02-03 07:52:45,945] Artifact SpringMVCdemo:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\User\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Tomcat_9_0_41_SpringMVCdemo"
Using CATALINA_HOME: "C:\Program Files\Apache Software Foundation\Tomcat 9.0"
Using CATALINA_TMPDIR: "C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk-15.0.1"
Using CLASSPATH: "C:\Program Files\Apache Software Foundation\Tomcat 9.0\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Tomcat 9.0\bin\tomcat-juli.jar"
Using CATALINA_OPTS: ""
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
03-Feb-2021 19:52:46.548 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.41
03-Feb-2021 19:52:46.549 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Dec 3 2020 11:43:00 UTC
03-Feb-2021 19:52:46.549 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.41.0
03-Feb-2021 19:52:46.549 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
03-Feb-2021 19:52:46.549 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Версия ОС: 10.0
03-Feb-2021 19:52:46.549 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Архитектура: amd64
03-Feb-2021 19:52:46.550 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk-15.0.1
03-Feb-2021 19:52:46.550 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Версия JVM: 15.0.1+9-18
03-Feb-2021 19:52:46.550 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
03-Feb-2021 19:52:46.550 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\User\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Tomcat_9_0_41_SpringMVCdemo
03-Feb-2021 19:52:46.550 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 9.0
03-Feb-2021 19:52:46.551 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
03-Feb-2021 19:52:46.551 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
03-Feb-2021 19:52:46.551 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\User\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Tomcat_9_0_41_SpringMVCdemo\conf\logging.properties
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=C:\Users\User\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Tomcat_9_0_41_SpringMVCdemo\jmxremote.password
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=C:\Users\User\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Tomcat_9_0_41_SpringMVCdemo\jmxremote.access
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
03-Feb-2021 19:52:46.552 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
03-Feb-2021 19:52:46.553 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
03-Feb-2021 19:52:46.553 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\User\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Tomcat_9_0_41_SpringMVCdemo
03-Feb-2021 19:52:46.553 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
03-Feb-2021 19:52:46.553 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp
03-Feb-2021 19:52:46.563 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.25] using APR version [1.7.0].
03-Feb-2021 19:52:46.563 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
03-Feb-2021 19:52:46.563 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
03-Feb-2021 19:52:46.566 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1g 21 Apr 2020]
03-Feb-2021 19:52:46.723 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
03-Feb-2021 19:52:46.748 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [347] milliseconds
03-Feb-2021 19:52:46.785 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
03-Feb-2021 19:52:46.785 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.41]
03-Feb-2021 19:52:46.791 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
03-Feb-2021 19:52:46.797 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [49] milliseconds
Connected to server
[2021-02-03 07:52:47,043] Artifact SpringMVCdemo:war exploded: Artifact is being deployed, please wait...
[2021-02-03 07:52:47,364] Artifact SpringMVCdemo:war exploded: Artifact is deployed successfully
[2021-02-03 07:52:47,364] Artifact SpringMVCdemo:war exploded: Deploy took 321 milliseconds
03-Feb-2021 19:52:56.801 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Установка веб приложения в папку [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\manager]
03-Feb-2021 19:52:56.879 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\manager] has finished in [78] ms
i have tried #RequestMapping(value="/", method = RequestMethod.GET) and ("/main-menu"). Serched stack for similar errors and used sugestions but nothing works. Tried creatign different project from scratch... It's driving me nuts, seems everything is done by the book but still errors
Why is your spring-mvc-demo-servlet.xml file the exact copy of web.xml? Try changing spring-mvc-demo-servlet.xml to:
<?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">
<mvc:annotation-driven />
<context:component-scan base-package="com.springmvcdemo" />
<mvc:default-servlet-handler />
<mvc:view-controller path="/" view-name="main-menu"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
OR...
In web.xml change the mapping as something similar as follows:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/demo/*</url-pattern>
</servlet-mapping>
You will append demo in your url as http://localhost:8080/demo/
This is the complete documentation in case you haven't seen it yet:
Configuring View Controllers
i posted wrong code for spring-mvc-demo-servlet.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:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="com.springmvcdemo" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>```
SOLVED
added extra mapping for method
#Controller
#RequestMapping
public class HomeController {
#RequestMapping("/home")
public String showPage(){
return "home-page";
}
}
added to web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
then lowered my language level to 13 since artifact could not deploy because of level 15 was unsupported by Spring (java.lang.IllegalArgumentException: Unsupported class file major version 59)
then i just call home page from browser
http://localhost:8080/SpringMVCdemo_war_exploded/home
Maybe this will help someone )
I am going to use Jenkins to execute the project automatically. The project is uploaded to github and succeeded in building War files using Jenkins. War file were moved to Tomcat's Webapps file, and Tomcat built it, but Tomcat runs properly, but projects don't run the project.
Setting
init_server.sh
echo "> Check the currently running spring server pid "
CURRENT_PID=$(ps -ef | grep java | grep tomcat | awk '{print $2}')
echo "$CURRENT_PID"
if [ -z $CURRENT_PID ]; then
echo "> No applications are currently running and will not be shut down."
else
echo "> kill -9 $CURRENT_PID"
kill -9 $CURRENT_PID
sleep 10
fi
rm -rf /usr/local/tomcat9/webapps/ji**t /usr/local/tomcat9/webapps/ji**t .war
echo nohup mv /root/jenkinsproject/deploy/*.war /usr/local/tomcat9/webapps/jinheeproject.war >> /root/jenkinsproject/logs/springtestprojectSys.log &
mv /root/jenkinsproject/deploy/*.war /usr/local/tomcat9/webapps/ji**t.war
sleep 10
cd /usr/local/tomcat9/bin
./startup.sh
echo "Execution complete."
application.yml
Run build in Jenkins, Follow the instructions in the Shell file, turn off the old Tomcat, and run the new Tomcat. And I type 'serverIP:8080' and the Tomcat server starts. But if I type 'serverIP:8080/helloworld', I see 404 error.
NOTE: I tested my project in the local environment. It was successful.
example: localhost:8080/helloworld
server.xml in cloud server
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" >
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="ji**t" reloadable="false" />
</Host>
my catalina logs
03-Mar-2020 16:55:23.226 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.31
03-Mar-2020 16:55:23.229 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Feb 5 2020 19:32:12 UTC
03-Mar-2020 16:55:23.230 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.31.0
03-Mar-2020 16:55:23.230 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
03-Mar-2020 16:55:23.230 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.4.0-59-generic
03-Mar-2020 16:55:23.230 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
03-Mar-2020 16:55:23.230 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-8-openjdk-amd64/jre
03-Mar-2020 16:55:23.231 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_242-8u242-b08-0ubuntu3~16.04-b08
03-Mar-2020 16:55:23.231 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Private Build
03-Mar-2020 16:55:23.232 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat9
03-Mar-2020 16:55:23.232 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat9
03-Mar-2020 16:55:23.233 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat9/conf/logging.properties
03-Mar-2020 16:55:23.233 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
03-Mar-2020 16:55:23.233 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
03-Mar-2020 16:55:23.233 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
03-Mar-2020 16:55:23.234 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
03-Mar-2020 16:55:23.234 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
03-Mar-2020 16:55:23.234 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat9
03-Mar-2020 16:55:23.234 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat9
03-Mar-2020 16:55:23.235 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat9/temp
03-Mar-2020 16:55:23.235 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/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]
03-Mar-2020 16:55:23.451 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
03-Mar-2020 16:55:23.498 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [518] milliseconds
03-Mar-2020 16:55:23.528 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
03-Mar-2020 16:55:23.528 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.31]
03-Mar-2020 16:55:27.202 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars 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.
03-Mar-2020 16:55:27.296 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat9/webapps/host-manager]
03-Mar-2020 16:55:27.328 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat9/webapps/host-manager] has finished in [31] ms
03-Mar-2020 16:55:27.328 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat9/webapps/manager]
03-Mar-2020 16:55:27.352 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat9/webapps/manager] has finished in [24] ms
03-Mar-2020 16:55:27.352 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat9/webapps/ROOTBEFORE]
03-Mar-2020 16:55:27.365 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat9/webapps/ROOTBEFORE] has finished in [12] ms
03-Mar-2020 16:55:27.365 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat9/webapps/docs]
03-Mar-2020 16:55:27.379 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat9/webapps/docs] has finished in [14] ms
03-Mar-2020 16:55:27.383 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
03-Mar-2020 16:55:27.391 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [3,892] milliseconds
There was something I was missing. I forgot to inherit SpringBootServletInitializer and set it up.
application.java
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I have a strange flow, when I'm trying to start the spring-mvc project, everything were building and starting correctly with localhost:8080 address, but it shows Apache Tomcat home page only and every request for example localhost:8080/login displays HTTP Status 404 – Not Found description:The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. Strange here is that, when I'm trying to run same project in another machine (Ubuntu) it works perfectly, login page appears correctly and every requests works fine. Strange thing also here is that, this unexpected flow came first time for this machine.
tomcat version is 8.5.24
this is my dispatcher-servlet.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>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
here is applicationContext.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:context="http://www.springframework.org/schema/context"
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">
<context:component-scan base-package="com.awesome"/>
</beans>
And here is my configuration class
#Configuration
#ComponentScan("com.awesome")
#EnableWebMvc
open class AppConfig : WebMvcConfigurerAdapter() {
#Bean
open fun viewResolver(): InternalResourceViewResolver {
val internalResourceViewResolver = InternalResourceViewResolver()
internalResourceViewResolver.setSuffix(".jsp")
internalResourceViewResolver.setPrefix("/")
return internalResourceViewResolver
}
override fun configureDefaultServletHandling(configurer: DefaultServletHandlerConfigurer?) {
configurer?.enable()
}
}
And here is controller
#Controller
class HomeController {
#RequestMapping("/", method = [(RequestMethod.GET)])
fun displayLoginPage(): String {
return "login"
}
#RequestMapping("/login", method = [(RequestMethod.POST)])
fun login(#RequestParam user_name:String, #RequestParam password: String, modelMap: ModelMap): String {
return "main"
}
}
and here is startup log
"C:\Program Files\apache-tomcat-8.5.24\bin\catalina.bat" run
[2018-01-22 03:18:25,411] Artifact Wall5:war: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\dev--\.IntelliJIdea2017.3\system\tomcat\Unnamed_Wall5"
Using CATALINA_HOME: "C:\Program Files\apache-tomcat-8.5.24"
Using CATALINA_TMPDIR: "C:\Program Files\apache-tomcat-8.5.24\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_144"
Using CLASSPATH: "C:\Program Files\apache-tomcat-8.5.24\bin\bootstrap.jar;C:\Program Files\apache-tomcat-8.5.24\bin\tomcat-juli.jar"
22-Jan-2018 15:18:26.852 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.24
22-Jan-2018 15:18:26.854 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov 27 2017 13:05:30 UTC
22-Jan-2018 15:18:26.854 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.24.0
22-Jan-2018 15:18:26.854 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_144\jre
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_144-b01
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\dev--\.IntelliJIdea2017.3\system\tomcat\Unnamed_Wall5
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Program Files\apache-tomcat-8.5.24
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\dev--\.IntelliJIdea2017.3\system\tomcat\Unnamed_Wall5\conf\logging.properties
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\dev--\.IntelliJIdea2017.3\system\tomcat\Unnamed_Wall5
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\apache-tomcat-8.5.24
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\apache-tomcat-8.5.24\temp
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
22-Jan-2018 15:18:27.854 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2m 2 Nov 2017]
22-Jan-2018 15:18:28.547 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
22-Jan-2018 15:18:28.563 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
22-Jan-2018 15:18:28.569 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
22-Jan-2018 15:18:28.571 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
22-Jan-2018 15:18:28.571 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2114 ms
22-Jan-2018 15:18:28.596 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
22-Jan-2018 15:18:28.596 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.24
22-Jan-2018 15:18:28.625 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
22-Jan-2018 15:18:28.638 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
22-Jan-2018 15:18:28.641 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 69 ms
I have fixed the problem, I just saw my artifacts and I have changed war artifact with exploded, now everything works fine.
In c turbo compiler first compile the code with zero error which is visible by pressing f9 then press ctrl+f9 for output then press alt+f5 the result will be visible on prompt window.
After upgrading my environment from Apache Tomcat 6.0.37 to 8.0.44 and Java from 1.7.0_45 to 1.8.0_131, one of my webapps will not deploy while the others run without issue.
My development environment is as follows.
Product Version: NetBeans IDE 8.2 (Build 201609300101)
Updates: NetBeans IDE is updated to version NetBeans 8.2 Patch 2
Java: 1.8.0_131; Java HotSpot(TM) 64-Bit Server VM 25.131-b11
Runtime: Java(TM) SE Runtime Environment 1.8.0_131-b11
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
User directory: C:\Users\heinzk\AppData\Roaming\NetBeans\8.2
Cache directory: C:\Users\heinzk\AppData\Local\NetBeans\Cache\8.2
When I attempt to run or debug my problematic webapp (which worked fine before these upgrades), I get the following server output.
Using CATALINA_BASE: "C:\Program Files\Apache Software Foundation\Tomcat 8.0"
Using CATALINA_HOME: "C:\Program Files\Apache Software Foundation\Tomcat 8.0"
Using CATALINA_TMPDIR: "C:\Program Files\Apache Software Foundation\Tomcat 8.0\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_131"
Using CLASSPATH: "C:\Program Files\Apache Software Foundation\Tomcat 8.0\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Tomcat 8.0\bin\tomcat-juli.jar"
Listening for transport dt_shmem at address: tomcat_shared_memory_id
20-Jun-2017 12:52:55.059 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.44
20-Jun-2017 12:52:55.064 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: May 10 2017 17:21:09 UTC
20-Jun-2017 12:52:55.064 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.44.0
20-Jun-2017 12:52:55.064 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 7
20-Jun-2017 12:52:55.064 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 6.1
20-Jun-2017 12:52:55.065 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
20-Jun-2017 12:52:55.065 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_131\jre
20-Jun-2017 12:52:55.065 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_131-b11
20-Jun-2017 12:52:55.065 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
20-Jun-2017 12:52:55.065 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Program Files\Apache Software Foundation\Tomcat 8.0
20-Jun-2017 12:52:55.065 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 8.0
20-Jun-2017 12:52:55.066 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Program Files\Apache Software Foundation\Tomcat 8.0\conf\logging.properties
20-Jun-2017 12:52:55.066 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
20-Jun-2017 12:52:55.066 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.jmxremote.port=9876
20-Jun-2017 12:52:55.066 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.jmxremote.ssl=false
20-Jun-2017 12:52:55.066 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.jmxremote.authenticate=false
20-Jun-2017 12:52:55.066 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dhttp.nonProxyHosts=localhost|127.0.0.1|US3C0771A3E9F2
20-Jun-2017 12:52:55.066 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
20-Jun-2017 12:52:55.067 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
20-Jun-2017 12:52:55.067 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_shmem,address=tomcat_shared_memory_id,server=y,suspend=n
20-Jun-2017 12:52:55.067 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 8.0\endorsed
20-Jun-2017 12:52:55.067 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Program Files\Apache Software Foundation\Tomcat 8.0
20-Jun-2017 12:52:55.067 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.0
20-Jun-2017 12:52:55.067 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 8.0\temp
20-Jun-2017 12:52:55.067 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_131\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Perforce;C:\Program Files (x86)\Tools;C:\Program Files\adt-bundle-windows-x86_64-20140321\sdk\tools;C:\Program Files\Git\cmd;C:\cygwin64\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Users\heinzk\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\WebEx\Productivity Tools;C:\Program Files (x86)\WebEx\PTools020000000;C:\Program Files (x86)\Scrivener;C:\Program Files (x86)\Scrivener\Aspell;C:\Program Files (x86)\Scrivener\Aspell\bin;.
20-Jun-2017 12:52:55.499 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
20-Jun-2017 12:52:59.671 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
20-Jun-2017 12:52:59.676 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
20-Jun-2017 12:52:59.685 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
20-Jun-2017 12:52:59.686 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 5325 ms
20-Jun-2017 12:52:59.751 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
20-Jun-2017 12:52:59.752 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.44
20-Jun-2017 12:52:59.765 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor C:\Program Files\Apache Software Foundation\Tomcat 8.0\conf\Catalina\localhost\Device_Monitor.xml
20-Jun-2017 12:53:05.430 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Device_Monitor]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:587)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1798)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at java.util.Hashtable.get(Hashtable.java:363)
at java.util.Properties.getProperty(Properties.java:969)
at org.apache.catalina.startup.ContextConfig.authenticatorConfig(ContextConfig.java:400)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:794)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:307)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5213)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 10 more
Unfortunately the NullPointerException on the HashTable is not of much help.
The context.xml file is and always has been as follows.
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/Device_Monitor"/>
Obviously there's a property being retrieved for which the property name is null. However, I have no idea which it might be as the stack trace is truncated.
Is there a way to get the balance of the "cause's" stack trace?
Is it possible that the context.xml file is incomplete for this new environment?
A sampling of the web.xml is as follows.
<?xml version="1.0" encoding="UTF-8"?>
<!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>Device Monitor</display-name>
<description>Device Monitor application to monitor devices</description>
<context-param>
<param-name>db_hostname</param-name>
<param-value>device-monitor-database</param-value>
<description>Database server hostname/IP address</description>
</context-param>
<context-param>
<param-name>db_name</param-name>
<param-value>device_monitor</param-value>
<description>Database schema name</description>
</context-param>
<context-param>
<param-name>db_password</param-name>
<param-value>device_monitor</param-value>
<description>Database account password</description>
</context-param>
<context-param>
<param-name>db_username</param-name>
<param-value>device_monitor</param-value>
<description>Database account username</description>
</context-param>
<context-param>
<param-name>db_trim_connections</param-name>
<param-value>True</param-value>
<description>Set true to dynamically trim database conections</description>
</context-param>
<context-param>
<param-name>max_HTTP_requests</param-name>
<param-value>25</param-value>
<description>Maximum number of HTTP requests that
may be processed at a time.
Set to "0" (zero) for no limit</description>
</context-param>
<servlet>
<servlet-name>DM Database</servlet-name>
<description>Start first to ensure table definitions are loaded
so any needed repairs can be initiated</description>
<servlet-class>database.Main</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>DM Message</servlet-name>
<description>Start next to ensure only old messages are cleared and
caches are preloaded</description>
<servlet-class>message.Main</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>DM GlobalSetting</servlet-name>
<description>This servlet is loaded next to read the global settings
stored in the database before anything other than messages starts</description>
<servlet-class>globalSetting.Main</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet>
<servlet-name>DM Device</servlet-name>
<description>Load after messages to update the health status of each
device per any uncleared messages</description>
<servlet-class>device.Main</servlet-class>
<init-param>
<param-name>removeDeletionsAfterMonths</param-name>
<param-value>6</param-value>
</init-param>
<init-param>
<param-name>deleteChangesAfterMonths</param-name>
<param-value>6</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DM Database</servlet-name>
<url-pattern>/Database</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DM Device</servlet-name>
<url-pattern>/Device</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DM Message</servlet-name>
<url-pattern>/Message</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DM GlobalSetting</servlet-name>
<url-pattern>/GlobalSetting</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>600</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<realm-name>Device-Monitor</realm-name>
</login-config>
</web-app>
After downloading and reviewing the pertinent the Tomcat source files as well as reading the javadocs and examining/comparing the context.xml and web.xml files between this projector and those that worked, I found that the following in my web.xml file was causing the issue.
<login-config>
<realm-name>Device-Monitor</realm-name>
</login-config>
After removing this login-config element my application started without issue.
It is odd to note that this did not cause an issue in my development environment under Tomcat 6.0 and Java 1.7.
I'm trying to start a new application from scratch with Spring 3.2, and I got the 404 error when I try to get access to my Controller. Here is my configuration:
WEB-INF
web.xml
web-context.xml
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>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/application-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/web-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/deblan/*</url-pattern>
</servlet-mapping>
</web-app>
web-context.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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">
<context:component-scan base-package="com.deboralandini.web.controllers"/>
<mvc:annotation-driven/>
<beans>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
</beans>
My controller:
package com.deboralandini.web.controllers;
import ...;
#Controller
#RequestMapping("cuenta")
public class CuentaController {
#Autowired
private CuentaService cuentaService;
...
#RequestMapping(value = "/cCuenta")
public String cCuenta(Model model){
return "crearCuenta";
}
...
}
My index.jsp:
<%# taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<html>
<body>
<h2>BlaBla</h2>
<br/>
Crear Cuenta
</body>
</html>
Unfortunately, when I click the link, I get:
Status HTTP 404 - /deblan/cuenta/cCuenta
The browser tries to make a GET to http://localhost:8080/deblan/cuenta/cCuenta, but I cannot get in my controller. I debugged the controller and in fact is not entering there, so: Whats my newbie error?
Thanks in advance
Marcos
Edit: this is my output:
"C:\...\App\tomcat8\bin\catalina.bat" run
[2014-10-21 08:57:21,069] Artifact DebLan:war: Server is not connected. Deploy is not available.
Using CATALINA_BASE: ...
Connected to the target VM, address: '127.0.0.1:64352', transport: 'socket'
21-Oct-2014 20:57:21.743 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.14
21-Oct-2014 20:57:21.745 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Sep 24 2014 09:01:51
21-Oct-2014 20:57:21.745 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.14.0
21-Oct-2014 20:57:21.745 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 8.1
21-Oct-2014 20:57:21.745 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 6.3
21-Oct-2014 20:57:21.745 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
21-Oct-2014 20:57:21.745 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.7.0_55-b13
21-Oct-2014 20:57:21.745 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
21-Oct-2014 20:57:21.924 INFO [main] org.apache.catalina.core.AprLifecycleListener.init Cargada la biblioteca nativa APR de Apache Tomcat 1.1.31 con la versión APR 1.4.8.
21-Oct-2014 20:57:21.924 INFO [main] org.apache.catalina.core.AprLifecycleListener.init Capacidades APR: IPv6 [true], enviar fichero [true], aceptar filtros [false], aleatorio [true].
21-Oct-2014 20:57:22.551 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL inicializado correctamente (OpenSSL 1.0.1h 5 Jun 2014)
21-Oct-2014 20:57:22.649 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
21-Oct-2014 20:57:22.662 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
21-Oct-2014 20:57:22.664 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 992 ms
21-Oct-2014 20:57:22.695 INFO [main] org.apache.catalina.core.StandardService.startInternal Arrancando servicio Catalina
21-Oct-2014 20:57:22.695 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.14
21-Oct-2014 20:57:22.708 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
21-Oct-2014 20:57:22.719 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
21-Oct-2014 20:57:22.722 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 57 ms
Connected to server
[2014-10-21 08:57:23,165] Artifact DebLan:war: Artifact is being deployed, please wait...
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[2014-10-21 08:57:32,003] Artifact DebLan:war: Artifact is deployed successfully
[2014-10-21 08:57:32,003] Artifact DebLan:war: Deploy took 8,838 milliseconds
21-Oct-2014 20:57:32.712 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Despliegue del directorio C:...\App\tomcat8\webapps\manager de la aplicación web
21-Oct-2014 20:57:32.762 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:...\App\tomcat8\webapps\manager has finished in 50 ms
If deblan is the context root then don't put it in the servlet mapping. You've got this url:
http://localhost:8080/deblan/cuenta/cCuenta
if you've deployed this app with deblan as the context root then:
http://localhost:8080/deblan
takes you to your app
/cuenta/cCuenta
now maps to your controller, so try:
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Which means http://localhost:8080/deblan + whatever comes after.