I have a problem with my spring app. While I run it, I am getting below exception:
It had worked correctly, but app didn't see changes in .jsp files and loaded the same page every time.
I faced with this problem in the past? but unfortunately I couldn't resolve this, and recreated project.
My project struct:
My spring-mvc-demo-servlet.xml file:
<?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.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.spring" />
<!-- 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>
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-mvc-demo</display-name>
<!-- Spring MVC Configs -->
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Maybe there is a problem with artifacts or tomcat configuration, because I changed it while tried resolve this error.
My pom.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.spring</groupId>
<artifactId>SpringgMVC</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>LATEST</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat</artifactId>
<version>8.5.39</version>
<type>pom</type>
</dependency>
</dependencies>
Update:::
I created a new artfacts, and received a new error:
my artifacts:
Although there are problem in web.xml.
Tomcat Log
"C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\catalina.bat" run
[2019-05-16 03:36:54,591] Artifact SpringgMVC:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\__it\.IntelliJIdea2018.3\system\tomcat\Unnamed_SpringgMVC"
Using CATALINA_HOME: "C:\Program Files\Apache Software Foundation\Tomcat 8.5"
Using CATALINA_TMPDIR: "C:\Program Files\Apache Software Foundation\Tomcat 8.5\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_151"
Using CLASSPATH: "C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\tomcat-juli.jar"
16-May-2019 15:36:55.256 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.39
16-May-2019 15:36:55.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Mar 14 2019 11:24:26 UTC
16-May-2019 15:36:55.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.39.0
16-May-2019 15:36:55.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
16-May-2019 15:36:55.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
16-May-2019 15:36:55.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
16-May-2019 15:36:55.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_151\jre
16-May-2019 15:36:55.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_151-b12
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\__it\.IntelliJIdea2018.3\system\tomcat\Unnamed_SpringgMVC
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 8.5
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\__it\.IntelliJIdea2018.3\system\tomcat\Unnamed_SpringgMVC\conf\logging.properties
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\__it\.IntelliJIdea2018.3\system\tomcat\Unnamed_SpringgMVC
16-May-2019 15:36:55.258 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.5
16-May-2019 15:36:55.259 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 8.5\temp
16-May-2019 15:36:55.259 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_151\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\ProgramData\Boxstarter;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Yarn\bin;C:\Program Files\dotnet\;C:\Program Files\Calibre2\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Program Files\TortoiseGit\bin;C:\Python27\gnuplot\binary;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\__it\AppData\Local\Microsoft\WindowsApps;C:\Users\__it\AppData\Local\Yarn\.bin;C:\Program Files\MongoDB\Server\3.4\bin;c:\Program Files\PhantomJS 2.1.1\bin;C:\ProgramData\Oracle\Java\javapath;;D:\PyCharm Community Edition 2018.3.5\bin;;.]
16-May-2019 15:36:55.334 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
16-May-2019 15:36:55.343 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
16-May-2019 15:36:55.355 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
16-May-2019 15:36:55.357 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
16-May-2019 15:36:55.357 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 381 ms
16-May-2019 15:36:55.372 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
16-May-2019 15:36:55.372 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.39
16-May-2019 15:36:55.378 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
16-May-2019 15:36:55.384 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
16-May-2019 15:36:55.384 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 27 ms
Connected to server
[2019-05-16 03:36:55,667] Artifact SpringgMVC:war exploded: Artifact is being deployed, please wait...
16-May-2019 15:36:57.032 INFO [RMI TCP Connection(3)-127.0.0.1] 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.
[2019-05-16 03:36:57,076] Artifact SpringgMVC:war exploded: Artifact is deployed successfully
[2019-05-16 03:36:57,077] Artifact SpringgMVC:war exploded: Deploy took 1 410 milliseconds
16-May-2019 15:37:05.382 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\manager]
16-May-2019 15:37:05.442 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\manager] has finished in [60] ms
Error is: Can not resolve servlet 'dispatcher'.
Pom.xml updated too above.
You can try maven tomcat plugin
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>9000</port> //Configure port number
<path>/spring5-webmvc-demo</path> //Configure application root URL
</configuration>
</plugin>
Then you can do a build mvn clean install and then mvn tomcat7:run
At least I resolved my problem. As told M. Deinum I have moved an web.xml, view, and spring-mvc-demo-servlet.xml to WEB-INF, because I have:
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
Then I regenerated an Artifacts.
Related
Following a udemy course, I have encountered this issue, to which the answer I didn't find anywhere.
I've had issues with the model class, but that seems to be working now.
URL pattern is fixed, by just being a /
for webmvc i have updated the dependency to be 4.3.6.RELEASE
Code itself and the server was running just before adding changes to the controller, enabling it to pass message value to the model.
Any help would be greatly appreciated.
HelloWebServlet.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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.luv2code.springdemo.mvc"/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemeLocation="
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>
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<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/HelloWeb-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
pom.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.luv2code.springweb</groupId>
<artifactId>spring-web-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>spring-web-demo Maven Webapp</name>
<url>http://localhost:8080/spring-web-demo</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.23</version>
</dependency>
</dependencies>
<build>
<finalName>spring-web-demo</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
HelloWorldController
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HelloWorldController {
#RequestMapping("/showForm")
public String showForm() {
return "helloworld-form";
}
#RequestMapping("/processForm")
public String processForm() {
return "helloworld";
}
#RequestMapping("/processFormVersionTwo")
public String letsShoutDude(HttpServletRequest request, Model model) {
String theName = request.getParameter("studentName");
theName = theName.toUpperCase();
String result = "Yo! " + theName;
model.addAttribute("message", result);
return "helloworld";
}
}
The error log
C:\Users\Slimas\.jdks\openjdk-17\bin\java.exe -Dcatalina.home=C:\Users\Slimas\Desktop\apache-tomcat-9.0.67 -Dcatalina.base=C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo -Djava.io.tmpdir=C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo\temp -Djava.util.logging.config.file=C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo\conf\logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\lib\idea_rt.jar=59958:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Slimas\Desktop\apache-tomcat-9.0.67\bin\bootstrap.jar;C:\Users\Slimas\Desktop\apache-tomcat-9.0.67\bin\tomcat-juli.jar org.apache.catalina.startup.Bootstrap start
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.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
05-Oct-2022 14:55:37.818 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.67
05-Oct-2022 14:55:37.820 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Sep 23 2022 11:22:29 UTC
05-Oct-2022 14:55:37.820 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.67.0
05-Oct-2022 14:55:37.820 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
05-Oct-2022 14:55:37.820 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
05-Oct-2022 14:55:37.820 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
05-Oct-2022 14:55:37.820 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Users\Slimas\.jdks\openjdk-17
05-Oct-2022 14:55:37.820 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 17+35-2724
05-Oct-2022 14:55:37.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
05-Oct-2022 14:55:37.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo
05-Oct-2022 14:55:37.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Users\Slimas\Desktop\apache-tomcat-9.0.67
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Users\Slimas\Desktop\apache-tomcat-9.0.67
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo\temp
05-Oct-2022 14:55:37.826 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo\conf\logging.properties
05-Oct-2022 14:55:37.827 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
05-Oct-2022 14:55:37.827 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\lib\idea_rt.jar=59958:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\bin
05-Oct-2022 14:55:37.827 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dfile.encoding=UTF-8
05-Oct-2022 14:55:37.828 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.35] using APR version [1.7.0].
05-Oct-2022 14:55:37.829 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
05-Oct-2022 14:55:37.829 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
05-Oct-2022 14:55:37.831 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1q 5 Jul 2022]
05-Oct-2022 14:55:37.985 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
05-Oct-2022 14:55:37.998 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [298] milliseconds
05-Oct-2022 14:55:38.023 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
05-Oct-2022 14:55:38.024 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.67]
05-Oct-2022 14:55:38.030 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo\conf\Catalina\localhost\spring-web-demo.xml]
05-Oct-2022 14:55:38.939 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.
05-Oct-2022 14:55:39.152 INFO [main] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'dispatcher': initialization started
05-Oct-2022 14:55:39.173 SEVERE [main] org.springframework.web.servlet.DispatcherServlet.initServletBean Context initialization failed
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.context.support.XmlWebApplicationContext]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:102)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:628)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1164)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1117)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4958)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5265)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:690)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1889)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:123)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:583)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:473)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1618)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:946)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:265)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:229)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:81)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:51)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.<init>(AbstractRefreshableWebApplicationContext.java:95)
at org.springframework.web.context.support.XmlWebApplicationContext.<init>(XmlWebApplicationContext.java:62)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 51 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.metrics.ApplicationStartup
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1412)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
... 62 more
05-Oct-2022 14:55:39.188 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [C:\Users\Slimas\.SmartTomcat\spring-web-demo\spring-web-demo\conf\Catalina\localhost\spring-web-demo.xml] has finished in [1,157] ms
05-Oct-2022 14:55:39.190 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
05-Oct-2022 14:55:39.220 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [1222] milliseconds
http://localhost:8080/spring-web-demo/
And lastly, the project structure:Image of project structure
As per advise
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.6.RELEASE</version>
Was changed to:
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.23</version>
Now it works.
Cheers!
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'm trying to create a project with Mojarra 2.3.8 and PrimeFaces 8.0 for Tomcat 8 Application server.
I used IntelliJ for building and testing my web application.
Following WELD installation instruction I installed all dependencies using maven, my pom file is:
<?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>groupId</groupId>
<artifactId>SensorWebHub3</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- dependencies for PrimeFaces -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>owasp-java-html-sanitizer</artifactId>
<version>20190503.1</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>8.0</version>
</dependency>
<!-- dependencies for CDI WELD -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>3.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.1.3.Final</version>
</dependency>
</dependencies>
</project>
I created the context.xml file in META-INF directory:
<Context>
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory" />
</Context>
I create an empty beans.xml file putted into WEB-INF directory; moreover I created the web.xml file:
<?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">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.LEGACY_WIDGET_NAMESPACE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>nova-light</param-value>
</context-param>
</web-app>
my simple index.xhtml file is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:outputLabel value="Hello, world"/>
<p:textEditor />
</f:view>
</html>
and my project structure is:
I configured IntelliJ IDEA in order to run Tomcat 8.5.54 Application server. When I run tomcat, it tries to deploy the war file but I get the following exception:
/Users/lerocchi/Tomcat-8.5.54/bin/catalina.sh run
[2020-04-15 06:10:22,449] Artifact swh3: Waiting for server connection to start artifact deployment...
15-Apr-2020 18:10:23.000 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/8.5.54
15-Apr-2020 18:10:23.001 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Apr 3 2020 14:06:10 UTC
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 8.5.54.0
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Mac OS X
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.15.4
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x86_64
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_45-b14
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3
15-Apr-2020 18:10:23.002 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /Users/lerocchi/Tomcat-8.5.54
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3/conf/logging.properties
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=/Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3/jmxremote.password
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=/Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3/jmxremote.access
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
15-Apr-2020 18:10:23.003 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
15-Apr-2020 18:10:23.004 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/Users/lerocchi/Library/Caches/JetBrains/IntelliJIdea2020.1/tomcat/Unnamed_SensorWebHub3
15-Apr-2020 18:10:23.004 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/Users/lerocchi/Tomcat-8.5.54
15-Apr-2020 18:10:23.004 INFORMAZIONI [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/Users/lerocchi/Tomcat-8.5.54/temp
15-Apr-2020 18:10:23.004 INFORMAZIONI [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/lerocchi/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
15-Apr-2020 18:10:23.104 INFORMAZIONI [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
15-Apr-2020 18:10:23.120 INFORMAZIONI [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
15-Apr-2020 18:10:23.131 INFORMAZIONI [main] org.apache.catalina.startup.Catalina.load Initialization processed in 422 ms
15-Apr-2020 18:10:23.156 INFORMAZIONI [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
15-Apr-2020 18:10:23.156 INFORMAZIONI [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.54
15-Apr-2020 18:10:23.163 INFORMAZIONI [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
15-Apr-2020 18:10:23.170 INFORMAZIONI [main] org.apache.catalina.startup.Catalina.start Server startup in 38 ms
Connected to server
[2020-04-15 06:10:23,540] Artifact swh3: Artifact is being deployed, please wait...
15-Apr-2020 18:10:23.956 AVVERTENZA [RMI TCP Connection(2)-127.0.0.1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
15-Apr-2020 18:10:25.895 INFORMAZIONI [RMI TCP Connection(2)-127.0.0.1] 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.
15-Apr-2020 18:10:25.931 INFO [RMI TCP Connection(2)-127.0.0.1] org.jboss.weld.environment.servlet.EnhancedListener.onStartup WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
15-Apr-2020 18:10:25.952 INFO [RMI TCP Connection(2)-127.0.0.1] org.jboss.weld.bootstrap.WeldStartup.<clinit> WELD-000900: 3.1.4 (Final)
15-Apr-2020 18:10:26.030 INFO [RMI TCP Connection(2)-127.0.0.1] org.jboss.weld.environment.deployment.discovery.DiscoveryStrategyFactory.create WELD-ENV-000020: Using jandex for bean discovery
15-Apr-2020 18:10:26.080 WARN [RMI TCP Connection(2)-127.0.0.1] org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize WELD-ENV-000028: Weld initialization skipped - no bean archive found
15-Apr-2020 18:10:26.122 INFORMAZIONI [RMI TCP Connection(2)-127.0.0.1] com.sun.faces.config.ConfigureListener.contextInitialized Initializing Mojarra 2.3.8 ( 20181116-0037 55af8b79ca53ec2df566f9c08a430259d30f9ba5) for context '/swh3'
15-Apr-2020 18:10:26.293 INFORMAZIONI [RMI TCP Connection(2)-127.0.0.1] com.sun.faces.spi.InjectionProviderFactory.createInstance JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
15-Apr-2020 18:10:26.434 GRAVE [RMI TCP Connection(2)-127.0.0.1] com.sun.faces.config.ConfigureListener.contextInitialized Critical error during deployment:
com.sun.faces.config.ConfigurationException: Factory 'javax.faces.lifecycle.ClientWindowFactory' was not configured properly.
at com.sun.faces.config.processor.FactoryConfigProcessor.verifyFactoriesExist(FactoryConfigProcessor.java:357)
at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:243)
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:443)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:237)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4699)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1720)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
...
...
I have no idea...
In web.xml added the listener for beans configurations:
<listener>
<listener-class>`org.jboss.weld.environment.servlet.Listener`</listener-class>
</listener>
And delete the following:
<listener>
<listenerclass>
org.apache.webbeans.servlet.WebBeansConfigurationListener
</listener-class>
</listener>
After several attempts, I found this solution:
I adopt OpenWebBeans instead the WELD solution:
I put the dependencies in my new pom.xml:
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0.SP1</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_2.0_spec</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.3_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>2.0.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>2.0.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>2.0.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-jsf</artifactId>
<version>2.0.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-el22</artifactId>
<version>2.0.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-tomcat7</artifactId>
<version>2.0.16</version>
<scope>compile</scope>
</dependency>
In web.xml I added the listener for beans configurations:
<?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">
<listener>
<listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
I changed the faces version into faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3" 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-facesconfig_2_3.xsd">
</faces-config>
The new context.xml file is moved into META-INF directory
<Context>
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.apache.webbeans.container.ManagerObjectFactory" />
</Context>
The new project structure is:
And now it works on Tomcat 8 server.
Im the beginner at web apps.
I tried to run the first application, but error occured.
I copied everything from the book, there everything works, at my place not...typically. I have been looking for hours for solution. Couldn't find.
I'm using 10.02 java, Apache Tomcat/9.0.12 and IntelliJ.
Here how my files structure looks like:
That is how configuration of Tomcat looks like:
HomeController
package com.packt.webstore.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HomeController {
#RequestMapping("/")
public String welcome(Model model) {
model.addAttribute("greeting", "Hello");
model.addAttribute("tagline", "In the internet");
return "welcome";
}
}
welcome.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<title>Witaj</title>
</head>
<body>
<section>
<div class="jumbotron">
<div class="container">
<h1> ${greeting} </h1>
<p> ${tagline} </p>
</div>
</div>
</section>
</body>
</html>
DefaultServletservlet.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.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.packt.webstore"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
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">
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DefaultServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
pom.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.packt</groupId>
<artifactId>webstore</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build><plugins><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin></plugins></build>
</project>
Here is stacktrace:
C:\Users\Admin\Desktop\apache-tomcat-9.0.12\bin\catalina.bat run
[2018-09-20 04:30:29,254] Artifact webstore:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\Admin\.IntelliJIdea2018.2\system\tomcat\Unnamed_webstore_2"
Using CATALINA_HOME: "C:\Users\Admin\Desktop\apache-tomcat-9.0.12"
Using CATALINA_TMPDIR: "C:\Users\Admin\Desktop\apache-tomcat-9.0.12\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk-10.0.2"
Using CLASSPATH: "C:\Users\Admin\Desktop\apache-tomcat-9.0.12\bin\bootstrap.jar;C:\Users\Admin\Desktop\apache-tomcat-9.0.12\bin\tomcat-juli.jar"
20-Sep-2018 16:30:31.591 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/9.0.12
20-Sep-2018 16:30:31.596 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Sep 4 2018 22:13:41 UTC
20-Sep-2018 16:30:31.596 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 9.0.12.0
20-Sep-2018 16:30:31.596 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 7
20-Sep-2018 16:30:31.597 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 6.1
20-Sep-2018 16:30:31.597 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
20-Sep-2018 16:30:31.597 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk-10.0.2
20-Sep-2018 16:30:31.597 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 10.0.2+13
20-Sep-2018 16:30:31.598 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: "Oracle Corporation"
20-Sep-2018 16:30:31.598 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\Admin\.IntelliJIdea2018.2\system\tomcat\Unnamed_webstore_2
20-Sep-2018 16:30:31.598 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Users\Admin\Desktop\apache-tomcat-9.0.12
20-Sep-2018 16:30:31.603 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
20-Sep-2018 16:30:31.603 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
20-Sep-2018 16:30:31.604 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
20-Sep-2018 16:30:31.604 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Admin\.IntelliJIdea2018.2\system\tomcat\Unnamed_webstore_2\conf\logging.properties
20-Sep-2018 16:30:31.604 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
20-Sep-2018 16:30:31.604 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
20-Sep-2018 16:30:31.604 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
20-Sep-2018 16:30:31.605 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
20-Sep-2018 16:30:31.605 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
20-Sep-2018 16:30:31.605 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
20-Sep-2018 16:30:31.605 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
20-Sep-2018 16:30:31.606 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
20-Sep-2018 16:30:31.606 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
20-Sep-2018 16:30:31.606 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Admin\.IntelliJIdea2018.2\system\tomcat\Unnamed_webstore_2
20-Sep-2018 16:30:31.606 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Users\Admin\Desktop\apache-tomcat-9.0.12
20-Sep-2018 16:30:31.606 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Users\Admin\Desktop\apache-tomcat-9.0.12\temp
20-Sep-2018 16:30:31.607 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\jdk-10.0.2\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Users\Admin\AppData\Local\GitHubDesktop\bin;.]
20-Sep-2018 16:30:31.690 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
20-Sep-2018 16:30:31.719 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
20-Sep-2018 16:30:31.732 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
20-Sep-2018 16:30:31.735 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
20-Sep-2018 16:30:31.736 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 949 ms
20-Sep-2018 16:30:31.880 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
20-Sep-2018 16:30:31.880 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.12
20-Sep-2018 16:30:31.909 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
20-Sep-2018 16:30:31.930 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
20-Sep-2018 16:30:31.937 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 200 ms
Connected to server
[2018-09-20 04:30:32,156] Artifact webstore:war exploded: Artifact is being deployed, please wait...
[2018-09-20 04:30:33,434] Artifact webstore:war exploded: Artifact is deployed successfully
[2018-09-20 04:30:33,434] Artifact webstore:war exploded: Deploy took 1 278 milliseconds
20-Sep-2018 16:30:41.920 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Users\Admin\Desktop\apache-tomcat-9.0.12\webapps\manager]
20-Sep-2018 16:30:42.028 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Users\Admin\Desktop\apache-tomcat-9.0.12\webapps\manager] has finished in [108] ms
And that's how page looks like: (I tried both http://localhost:8080/ and http://localhost:8080/webstore
`
///EDIT
Updated project according to #Ce7 's post .
Project Structure
pom.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.packt</groupId>
<artifactId>webstore</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>webapp</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
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">
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/DefaultServlet-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DefaultServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Stacktrace
(i had to paste it on pastebin, because question is too long)
https://pastebin.com/SS0uVKjU
Page
Config you pom properly, your current configuration is creating jar file, instead of war, and you don't have maven war plugin to put your web resource (jsp, web.xml, etc) into the war file.
<groupId>com.packt</groupId>
<artifactId>webstore</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>webapp</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Put your WEB-INF folder under a root folder, for example webapp/WEB-INF, here webapp folder is in same level as src folder
Rename your DefaultServeletservlet.xml to
DefaultServelet-servlet.xml
Modify web.xml file to config DefaultServlet.
<servlet>
...
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/DefaultServlet-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
After all of this, deploy it, then you should see something like this:
The problem with the above is that you have named your servlet configuration file as DefaultServletservlet.xml.
Instead you should rename it as DefaultServlet-servlet.xml. While checking for the xml configuration spring matches the filename with -servlet as a suffix. As it is not able to find DefaultServlet-servlet.xml, hence the error.
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: