Regarding problem in building Session factory - java

`
Using CATALINA_BASE: "C:\apache-tomcat-10.0.22"
Using CATALINA_HOME: "C:\apache-tomcat-10.0.22"
Using CATALINA_TMPDIR: "C:\apache-tomcat-10.0.22\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk-11.0.13"
Using CLASSPATH: "C:\apache-tomcat-10.0.22\bin\bootstrap.jar;C:\apache-tomcat-10.0.22\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.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
01-Jul-2022 16:46:59.074 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/10.0.22
01-Jul-2022 16:46:59.079 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 2 2022 16:53:56 UTC
01-Jul-2022 16:46:59.079 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.0.22.0
01-Jul-2022 16:46:59.079 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
01-Jul-2022 16:46:59.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
01-Jul-2022 16:46:59.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
01-Jul-2022 16:46:59.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk-11.0.13
01-Jul-2022 16:46:59.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 11.0.13+10-LTS-370
01-Jul-2022 16:46:59.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
01-Jul-2022 16:46:59.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\apache-tomcat-10.0.22
01-Jul-2022 16:46:59.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\apache-tomcat-10.0.22
01-Jul-2022 16:46:59.106 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
01-Jul-2022 16:46:59.106 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
01-Jul-2022 16:46:59.106 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
01-Jul-2022 16:46:59.106 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
01-Jul-2022 16:46:59.106 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\apache-tomcat-10.0.22\conf\logging.properties
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dhttp.nonProxyHosts=localhost|127.0.0.1|DESKTOP-BBI82LE
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\apache-tomcat-10.0.22
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\apache-tomcat-10.0.22
01-Jul-2022 16:46:59.107 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\apache-tomcat-10.0.22\temp
01-Jul-2022 16:46:59.333 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
01-Jul-2022 16:46:59.333 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
01-Jul-2022 16:46:59.343 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1o 3 May 2022]
01-Jul-2022 16:46:59.891 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
01-Jul-2022 16:46:59.935 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [1225] milliseconds
01-Jul-2022 16:47:00.045 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
01-Jul-2022 16:47:00.045 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.0.22]
01-Jul-2022 16:47:00.061 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [C:\apache-tomcat-10.0.22\conf\Catalina\localhost\mycart.xml]
01-Jul-2022 16:47:00.087 WARNING [main] org.apache.catalina.startup.HostConfig.deployDescriptor The path attribute with value [/mycart] in deployment descriptor [C:\apache-tomcat-10.0.22\conf\Catalina\localhost\mycart.xml] has been ignored
01-Jul-2022 16:47:02.383 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.
01-Jul-2022 16:47:02.731 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [295] milliseconds.
01-Jul-2022 16:47:02.777 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [C:\apache-tomcat-10.0.22\conf\Catalina\localhost\mycart.xml] has finished in [2,716] ms
01-Jul-2022 16:47:02.779 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-10.0.22\webapps\docs]
01-Jul-2022 16:47:02.833 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-10.0.22\webapps\docs] has finished in [53] ms
01-Jul-2022 16:47:02.834 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-10.0.22\webapps\examples]
01-Jul-2022 16:47:03.557 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-10.0.22\webapps\examples] has finished in [723] ms
01-Jul-2022 16:47:03.559 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-10.0.22\webapps\host-manager]
01-Jul-2022 16:47:03.635 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-10.0.22\webapps\host-manager] has finished in [75] ms
01-Jul-2022 16:47:03.635 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-10.0.22\webapps\manager]
01-Jul-2022 16:47:03.715 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-10.0.22\webapps\manager] has finished in [80] ms
01-Jul-2022 16:47:03.716 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-10.0.22\webapps\ROOT]
01-Jul-2022 16:47:03.792 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-10.0.22\webapps\ROOT] has finished in [75] ms
01-Jul-2022 16:47:03.800 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
01-Jul-2022 16:47:04.176 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [4240] milliseconds
01-Jul-2022 16:49:37.103 INFO [http-nio-8080-exec-1] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/mycart]
01-Jul-2022 16:49:37.168 INFO [http-nio-8080-exec-7] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [C:\apache-tomcat-10.0.22\conf\Catalina\localhost\mycart.xml]
01-Jul-2022 16:49:37.170 WARNING [http-nio-8080-exec-7] org.apache.catalina.startup.HostConfig.deployDescriptor The path attribute with value [/mycart] in deployment descriptor [C:\apache-tomcat-10.0.22\conf\Catalina\localhost\mycart.xml] has been ignored
01-Jul-2022 16:49:38.991 INFO [http-nio-8080-exec-7] 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.
01-Jul-2022 16:49:38.997 INFO [http-nio-8080-exec-7] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [C:\apache-tomcat-10.0.22\conf\Catalina\localhost\mycart.xml] has finished in [1,829] ms
01-Jul-2022 16:49:39.004 INFO [http-nio-8080-exec-5] org.apache.catalina.util.LifecycleBase.start The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/mycart]] after start() had already been called. The second call will be ignored.
01-Jul-2022 16:49:42.716 INFO [http-nio-8080-exec-2] org.hibernate.Version.logVersion HHH000412: Hibernate ORM core version 5.4.20.Final
org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 17 and column 27 in RESOURCE hibernate.cfg.xml. Message: cvc-complex-type.2.3: Element 'session-factory' cannot have character [children], because the type's content type is element-only.
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:134)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:66)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:234)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at com.learn.mycart.helper.FactoryProvider.getFactory(FactoryProvider.java:22)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:133)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:356)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:867)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1760)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 27; cvc-complex-type.2.3: Element 'session-factory' cannot have character [children], because the type's content type is element-only.]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:483)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:463)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:435)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:127)
... 34 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 27; cvc-complex-type.2.3: Element 'session-factory' cannot have character [children], because the type's content type is element-only.
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:135)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:511)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3587)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(XMLSchemaValidator.java:3472)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3432)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3334)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(XMLSchemaValidator.java:2372)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:943)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:584)
at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.endElement(ValidatingUnmarshaller.java:106)
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.endElement(InterningXmlVisitor.java:81)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXEventConnector.handleEndElement(StAXEventConnector.java:234)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(StAXEventConnector.java:135)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:460)
... 36 more
enter image description here
//hibernate_cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory> //this tag is used to configure and initialize the session factory settings for hibernate such as Dialect class and connection Driver class properties
<property name = "connection.driver_class">com.mysql.cj.jdbc.Driver"</property>
<property name = "connection.url">jdbc:mysql://localhost:3306/mycart</property>
<property name = "connection.username">root</property>
<property name = "connection.password">root</property>
<property name = "dialect">org.hibernate.dialect.MySQL57Dialect</property>
<property name = "hbm2ddl.auto">update </property>
<property name = "show_sql"> true</property>/>
</session-factory>
</hibernate-configuration>
//index.jsp
<%--
Document : index
Created on : 27-Jun-2022, 9:43:58 AM
Author : Pankaj Yadav
--%>
<%#page import="com.learn.mycart.helper.FactoryProvider"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<<h1> Creating session factory object</h1>
<%
out.println( FactoryProvider.getFactory());
%>
</body>
</html>
//FactoryProvider.java
package com.learn.mycart.helper;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
*
* #author Pankaj Yadav
*/
public class FactoryProvider
{
private static SessionFactory factory;
public static SessionFactory getFactory()
{
try
{
if(factory == null)
{
factory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
}
}catch(Exception e)
{
e.printStackTrace();
}
return factory;
}
}
<%--
Document : index
Created on : 27-Jun-2022, 9:43:58 AM
Author : Pankaj Yadav
--%>
<%#page import="com.learn.mycart.helper.FactoryProvider"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<<h1> Creating session factory object</h1>
<%
out.println( FactoryProvider.getFactory());
%>
</body>
</html>
//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.mycompany</groupId>
<artifactId>mycart</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>mycart</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.20.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
`I am makinga an project and in building session factory object I am getting an error called "Caused by: javax.xml.bind.UnmarshalException
with linked exception:"
After running the code we should get the reference hash code for the session factory, and object of session factory implementation class,but I am getting null only. I am attaching the screenshot of the output that I am getting and the correct output. Also, I am sharing the "pom.xml" code, "hibernate.cfg.xml" code and "Factory Provider. java" code and "Indesx.jsp code" module of my project. Please check and do let me know where is the error? Please help
enter image description here
Caused by: javax.xml.bind.UnmarshalException
with linked exception:
enter image description here

Related

IntelliJ MVC Server Context initialization failed

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!

Spring Application gets 404 error on TomCat

how are u?
I'm doing a Spring Boot Application and i'm getting the 404 error on TomCat. I'm using Maven to build the .WAR file and do the deploy to TomCat with the tomcat7-maven-plugin. I already read a lot of topics with a context very similar to mine but i cant find a solution.
Something that i notice, is that when i do the deploy, the Spring Letters not show anymore on TomCat prompt.
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/scim/] is not available
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.64
Print of the error
Some dudes try to resolve this putting extends SpringBootServletInitializer and the
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
return builder.sources(ScimApplication.class);
}
on the main class, but i already did that, and didn't worked.
I used to compile the .war file with the mvn clean install command, then i do the mvn clean tomcat7:deploy to do the deploy directly to the TomCat, that i already configurated the user on tomcat-users.xml, and add the server tag on the settings.xml on conf folder of Maven.
Even if i enter on the TomCat's manager page, and do the deploy from there, when i try localhost:8080/scim, i get 404 error.
I will put my initialization TomCat log here, as well my Controller, POM.xml and Main class.
Thank you and if you guys need more information, just tell me.
TomCat Log Initialization
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 2 2022 19:08:46 UTC
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.64.0
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jre1.8.0_333
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_333-b02
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=\apache-tomcat-9.0.64\conf\logging.properties
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=\apache-tomcat-9.0.64\temp
07-Jul-2022 11:09:14.811 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
07-Jul-2022 11:09:14.811 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
07-Jul-2022 11:09:14.827 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
07-Jul-2022 11:09:14.827 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1o 3 May 2022]
07-Jul-2022 11:09:15.215 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
07-Jul-2022 11:09:15.265 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [710] milliseconds
07-Jul-2022 11:09:15.297 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
07-Jul-2022 11:09:15.297 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.64]
07-Jul-2022 11:09:15.328 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\apache-tomcat-9.0.64\webapps\scim.war]
07-Jul-2022 11:09:19.655 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.
07-Jul-2022 11:09:20.057 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [269] milliseconds.
07-Jul-2022 11:09:20.075 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [C:\apache-tomcat-9.0.64\webapps\scim.war] has finished in [4,747] ms
07-Jul-2022 11:09:20.075 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\docs]
07-Jul-2022 11:09:20.127 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\docs] has finished in [52] ms
07-Jul-2022 11:09:20.127 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\examples]
07-Jul-2022 11:09:20.684 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\examples] has finished in [557] ms
07-Jul-2022 11:09:20.684 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\host-manager]
07-Jul-2022 11:09:20.757 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\host-manager] has finished in [72] ms
07-Jul-2022 11:09:20.757 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\manager]
07-Jul-2022 11:09:20.794 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\manager] has finished in [37] ms
07-Jul-2022 11:09:20.794 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\ROOT]
07-Jul-2022 11:09:20.849 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\ROOT] has finished in [55] ms
07-Jul-2022 11:09:20.849 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
07-Jul-2022 11:09:20.866 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [5601] milliseconds
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ushin</groupId>
<artifactId>scim</artifactId>
<name>scim</name>
<description>scim</description>
<packaging>war</packaging>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!--Spring-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!--MySQL-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
<build>
<finalName>scim</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Users\gbrasolin\.jdks\corretto-11.0.15\bin\javac.exe</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>scim</server>
<path>/scim</path>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Controller
package com.ushin.scim.controllers;
import com.ushin.scim.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
#Controller
#RequestMapping(value = "/Users")
public class UserController {
UserService userService;
#Autowired
public UserController(UserService userService) {
this.userService = userService;
}
#RequestMapping(method = RequestMethod.POST)
public #ResponseBody Map createUser(#RequestBody Map<String, Object> payload, HttpServletResponse response){
return userService.createUser(payload, response);
}
#RequestMapping(method = RequestMethod.GET)
public #ResponseBody Map getUsers(#RequestParam Map<String, String> payload) throws IOException {
return userService.getUsers(payload);
}
#RequestMapping(value = "/{id}")
public #ResponseBody Map getSingleUser (#PathVariable String id, HttpServletResponse response){
return userService.getSingleUser(id, response);
}
#RequestMapping(method = RequestMethod.PUT, value = "/{id}")
public #ResponseBody Map updateUser(#RequestBody Map<String, Object> payload, #PathVariable String id){
return userService.updateUser(payload, id);
}
#RequestMapping(method = RequestMethod.PATCH, value = "/{id}")
public #ResponseBody Map disableUser (#RequestBody Map<String, Object> payload, #PathVariable String id){
return userService.disableUser(payload, id);
}
}
Main Class
package com.ushin.scim;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
#SpringBootApplication
public class ScimApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ScimApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
return builder.sources(ScimApplication.class);
}
}
I changed the JRE_HOME (was running java 8) to the same path of JAVA_HOME which is with Java 11, and it worked. Tomcat was on Java 8 and my project was running Java 11.
Log:
Using JRE_HOME: "C:\Program Files\Java\jre1.8.0_333"
My POM.xml:
<java.version>11</java.version>

HTTP Status 404 – Not Found during hello world

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.

Tomcat + Spring deploying error

I need help. I run spring java server under tomcat.
2-Sep-2017 10:35:52.595 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.20
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Aug 2 2017 21:35:49 UTC
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.20.0
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 7
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 6.1
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_144\jre
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_144-b01
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\Bosun\.IntelliJIdea2017.2\system\tomcat\Unnamed_beautifulmindonlineserver
02-Sep-2017 10:35:52.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Users\Bosun\Desktop\apache-tomcat-8.5.20
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Bosun\.IntelliJIdea2017.2\system\tomcat\Unnamed_beautifulmindonlineserver\conf\logging.properties
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Bosun\.IntelliJIdea2017.2\system\tomcat\Unnamed_beautifulmindonlineserver
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Users\Bosun\Desktop\apache-tomcat-8.5.20
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Users\Bosun\Desktop\apache-tomcat-8.5.20\temp
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.12] using APR version [1.5.2].
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
02-Sep-2017 10:35:52.611 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
02-Sep-2017 10:35:53.641 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2k 26 Jan 2017]
02-Sep-2017 10:35:54.280 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
02-Sep-2017 10:35:54.311 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
02-Sep-2017 10:35:54.327 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
02-Sep-2017 10:35:54.327 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
02-Sep-2017 10:35:54.327 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2528 ms
02-Sep-2017 10:35:54.405 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
02-Sep-2017 10:35:54.405 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.20
02-Sep-2017 10:35:54.436 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
02-Sep-2017 10:35:54.452 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
02-Sep-2017 10:35:54.452 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 125 ms
Connected to server
[2017-09-02 10:35:54,889] Artifact beautifulmindonlineserver:war: Artifact is being deployed, please wait...
02-Sep-2017 10:36:00.224 INFO [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.
02-Sep-2017 10:36:02.938 INFO [RMI TCP Connection(2)-127.0.0.1] org.hibernate.jpa.internal.util.LogHelper.logPersistenceUnitInformation HHH000204: Processing PersistenceUnitInfo [
name: default
...]
02-Sep-2017 10:36:03.281 INFO [RMI TCP Connection(2)-127.0.0.1] org.hibernate.Version.logVersion HHH000412: Hibernate Core {5.2.10.Final}
02-Sep-2017 10:36:03.281 INFO [RMI TCP Connection(2)-127.0.0.1] org.hibernate.cfg.Environment.<clinit> HHH000205: Loaded properties from resource hibernate.properties: {hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect, hibernate.show_sql=true, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=validate}
02-Sep-2017 10:36:03.578 INFO [RMI TCP Connection(2)-127.0.0.1] org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit> HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
02-Sep-2017 10:36:04.451 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Users\Bosun\Desktop\apache-tomcat-8.5.20\webapps\manager]
02-Sep-2017 10:36:04.561 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Users\Bosun\Desktop\apache-tomcat-8.5.20\webapps\manager] has finished in [94] ms
02-Sep-2017 10:36:04.873 INFO [RMI TCP Connection(2)-127.0.0.1] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
02-Sep-2017 10:36:05.450 INFO [RMI TCP Connection(2)-127.0.0.1] org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.useContextualLobCreation HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
02-Sep-2017 10:36:05.450 INFO [RMI TCP Connection(2)-127.0.0.1] org.hibernate.type.BasicTypeRegistry.register HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType#4d851601
02-Sep-2017 10:36:07.774 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
02-Sep-2017 10:36:07.774 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
02-Sep-2017 10:36:07.821 WARNING [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [ROOT] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
[2017-09-02 10:36:07,868] Artifact beautifulmindonlineserver:war: Error during artifact deployment. See server log for details.
hybernate.properties file
hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=validate
I found that if I comment this line
public interface UsersRepository extends JpaRepository {
}
in UserRepository file related to my User ORM class, everything compiled well.
My dependencies:
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<!--Web-->
<!--Json converter-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
</dependency>
<!-- Database-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-entitymanager.version}</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>${commons-dbcp2.version}</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
As I am novice in server-side development and spring, ask for extended response.
UPDATED:
package com.blackbosun.beatufilmind.server;
import com.blackbosun.beatufilmind.server.config.WebConfig;
import com.blackbosun.beatufilmind.server.repository.UsersRepository;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
public class Application implements WebApplicationInitializer {
private final static String DISPATCHER = "dispatcher";
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(WebConfig.class);
servletContext.addListener(new ContextLoaderListener(ctx));
ServletRegistration.Dynamic servlet = servletContext.addServlet(DISPATCHER, new DispatcherServlet(ctx));
servlet.addMapping("/");
servlet.setLoadOnStartup(1);
}
}

Leaking Tomcat JDBC MySQL driver in a Spring environment

At the moment I am writing a Spring and JDBC based web-application that interacts with a MySQL database on a Windows Server 2012 x64. The MySQL database driver is registered by Tomcat and not by the servlet itself (As so many people do).
Although I close all connection/prepared statements/result sets, Tomcat logs a possible memory leak during a restart and I don't know why. Additionally the server crashes (Read: times out) after a few days, maybe because the leaks.
$APACHE_DIR/conf/context.xml:
<?xml version='1.0' encoding='utf-8'?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Resource name="jdbc/testservlet"
global="jdbc/testservlet"
type="javax.sql.DataSource"
username="root"
password="123456aA"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testservlet"
maxTotal="10"
maxIdle="10"
maxWaitMillis="10000"
removeAbandonedTimeout="300"
defaultAutoCommit="true" />
</Context>
$APACHE_DIR/webapps/testservlet/META-INF/context.xml:
<?xml version='1.0' encoding='utf-8'?>
<Context>
<ResourceLink name="jdbc/testservlet" global="jdbc/testservlet" type="javax.sql.DataSource" />
</Context>
$PROJECT_DIR/DatabaseConfiguration.java
package com.example.testservlet.configuration;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
public class DatabaseConfiguration
{
#Bean
public DataSource getDataSource() throws Exception
{
Context initialContext = new InitialContext();
Context environmentContext = (Context) initialContext.lookup("java:comp/env");
DataSource dataSource = (DataSource) environmentContext.lookup("jdbc/testservlet");
return dataSource;
}
}
$PROJECT_DIR/HomeController.java
package com.example.testservlet.controller;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
#Controller
public class HomeController
{
#Autowired
DataSource datasource;
#ResponseBody
#RequestMapping(value = "/", method = RequestMethod.GET)
public void home() throws Exception
{
Connection connection = null;
ResultSet resultset = null;
try
{
connection = datasource.getConnection();
DatabaseMetaData metadata = connection.getMetaData();
resultset = metadata.getTables(null, null, "%", null);
while(resultset.next())
{
System.out.println("Table: " + resultset.getString(3));
}
}
finally
{
System.out.println("Final block start");
try{ connection.close(); } catch(Exception exception) { throw new Exception("Database error"); }
try{ resultset.close(); } catch(Exception exception) { throw new Exception("Database error"); }
System.out.println("Final block end");
}
}
}
$PROJECT_ROOT/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>testservlet</artifactId>
<packaging>war</packaging>
<version>0.1.0-SNAPSHOT</version>
<name>testservlet</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>testservlet</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<webResources>
<resource>
<directory>${project.basedir}/src/main/resources
</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
The MySQL driver is installed as "mysql-connector-java.jar" (Version 5.1.38) inside the Tomcat lib directory also the database configuration is called by the Spring framework. A HTTP request to localhost:8080/testservlet + a Tomcat restarts results in the following log:
25-Jan-2016 19:11:28.006 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.30
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Dec 1 2015 22:30:46 UTC
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.30.0
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows Server 2012 R2
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 6.3
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_66\jre
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_66-b18
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64\conf\logging.properties
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64\endorsed
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64\temp
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.1.33 using APR version 1.5.1.
25-Jan-2016 19:11:28.037 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
25-Jan-2016 19:11:28.617 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.1m 19 Mar 2015)
25-Jan-2016 19:11:28.866 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
25-Jan-2016 19:11:28.881 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
25-Jan-2016 19:11:28.881 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1407 ms
25-Jan-2016 19:11:28.929 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
25-Jan-2016 19:11:28.929 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.30
25-Jan-2016 19:11:29.006 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64\webapps\testservlet.war
25-Jan-2016 19:11:30.901 INFO [localhost-startStop-1] org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance Name = testservlet Ignoring unknown property: value of "JCG Example MySQL database." for "description" property
25-Jan-2016 19:11:30.901 INFO [localhost-startStop-1] org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance Name = testservlet Ignoring unknown property: value of "jdbc/testservlet" for "global" property
25-Jan-2016 19:11:31.010 INFO [localhost-startStop-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.
25-Jan-2016 19:11:31.213 INFO [localhost-startStop-1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started
25-Jan-2016 19:11:31.213 INFO [localhost-startStop-1] org.springframework.web.context.support.AnnotationConfigWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Mon Jan 25 19:11:31 CET 2016]; root of context hierarchy
25-Jan-2016 19:11:31.369 INFO [localhost-startStop-1] org.springframework.web.context.support.AnnotationConfigWebApplicationContext.loadBeanDefinitions Found 2 annotated classes in package [com.example.testservlet.configuration]
25-Jan-2016 19:11:32.141 INFO [localhost-startStop-1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void com.example.testservlet.controller.HomeController.home() throws java.lang.Exception
25-Jan-2016 19:11:32.187 INFO [localhost-startStop-1] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandler Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]
25-Jan-2016 19:11:32.437 INFO [localhost-startStop-1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for #ControllerAdvice: Root WebApplicationContext: startup date [Mon Jan 25 19:11:31 CET 2016]; root of context hierarchy
25-Jan-2016 19:11:32.671 INFO [localhost-startStop-1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization completed in 1458 ms
25-Jan-2016 19:11:32.749 INFO [localhost-startStop-1] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'DispatcherServlet': initialization started
25-Jan-2016 19:11:32.781 INFO [localhost-startStop-1] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'DispatcherServlet': initialization completed in 32 ms
25-Jan-2016 19:11:32.829 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\Users\simonwaechter\Downloads\apache-tomcat-8.0.30-windows-x64\webapps\testservlet.war has finished in 3,807 ms
25-Jan-2016 19:11:32.829 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
25-Jan-2016 19:11:32.843 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
25-Jan-2016 19:11:32.843 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 3959 ms
25-Jan-2016 19:11:45.074 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
25-Jan-2016 19:11:45.074 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-apr-8080"]
25-Jan-2016 19:11:45.137 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-apr-8009"]
25-Jan-2016 19:11:45.199 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
25-Jan-2016 19:11:45.199 INFO [localhost-startStop-2] org.springframework.web.context.support.AnnotationConfigWebApplicationContext.doClose Closing Root WebApplicationContext: startup date [Mon Jan 25 19:11:31 CET 2016]; root of context hierarchy
25-Jan-2016 19:11:45.199 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [testservlet] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
25-Jan-2016 19:11:45.215 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-apr-8080"]
25-Jan-2016 19:11:45.309 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-apr-8009"]
25-Jan-2016 19:11:45.371 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-apr-8080"]
25-Jan-2016 19:11:45.371 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-apr-8009"]
I have no idea why this leak happens. There are many answers like deregistering the JDBC driver, but few of them handle the driver in a shared/hosted Tomcat environment where other servlets might access the same JDBC driver.
We ended up with the answer from Guillaume and use the listener.
I still don't know what caused the sporadic crashes, but an update of the Oracle MySQL server solved the problem.

Categories

Resources