Servlet-MongoDb Project :Db connection - java

I develop basic user management project using Servlet-JSP-MongoDB.My codes are bellow.After I run project on Tomcat ,I take exception on console as follows.
Why is this problem,please help me?
package com.fatih.controller;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fatih.dao.UserDAO;
import com.fatih.model.User;
import com.mongodb.MongoClient;
/**
* Servlet implementation class AddUser
*/
#WebServlet("/addUser")
public class AddUser extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public AddUser() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name=request.getParameter("name");
String email=request.getParameter("emailId");
String password=request.getParameter("password");
if( (name==null || name.equals(""))||
(email==null || email.equals(""))||
(password==null || password.equals(""))){
request.setAttribute("error", "All fields are required!");
RequestDispatcher dispatcher=getServletContext().getRequestDispatcher("/users.jsp");
dispatcher.forward(request, response);
}else{
User user=new User();
user.setName(name);
user.setEmail(email);
user.setPassword(password);
MongoClient mongoClient=(MongoClient) request.getServletContext().getAttribute("MONGO_CLIENT");
UserDAO userDAO=new UserDAO(mongoClient);
userDAO.createUser(user);
request.setAttribute("success", "User added");
RequestDispatcher dispatcher=getServletContext().getRequestDispatcher("/users.jsp");
dispatcher.forward(request, response);
}
System.out.println("name: "+name+"\nemail: "+email+"\npassword: "+password);
}
}
.......................................................................
package com.fatih.conventer;
import org.bson.types.ObjectId;
import com.fatih.model.User;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;
public class UserConventer {
public static DBObject toDBObject(User user) {
BasicDBObjectBuilder builder=BasicDBObjectBuilder.start()
.append("name", user.getName())
.append("email", user.getEmail())
.append("password", user.getPassword());
if(user.getId()!=null){
builder=builder.append("_id", new ObjectId(user.getId()));
}
return builder.get();
}
}
..........................................................................
package com.fatih.dao;
import org.bson.types.ObjectId;
import com.fatih.conventer.UserConventer;
import com.fatih.model.User;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
public class UserDAO {
private DBCollection dbCollection;
public UserDAO(MongoClient mongoClient) {
this.dbCollection=mongoClient.getDB("usersDB").getCollection("users");
}
public User createUser(User user){
DBObject dbObject=UserConventer.toDBObject(user);
this.dbCollection.insert(dbObject);
ObjectId id=(ObjectId) dbObject.get("_id");
user.setId(id.toString());
return user;
}
}
..........................................................
package com.fatih.listener;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import com.mongodb.MongoClient;
#WebListener
public class MongoDBListener implements ServletContextListener{
#Override
public void contextDestroyed(ServletContextEvent sce) {
MongoClient mongoClient=(MongoClient) sce.getServletContext().getAttribute("MONGO_CLIENT");
mongoClient.close();
}
#Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context=sce.getServletContext();
MongoClient mongoClient=new MongoClient(context.getInitParameter("MONGO_HOST"),Integer.parseInt(context.getInitParameter("MONGO_PORT")));
sce.getServletContext().setAttribute("MONGO_CLIENT", mongoClient);
}
}
......................................................................
package com.fatih.model;
public class User {
private String id;
private String name;
private String email;
private String password;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>KullaniciYonetimSistemiMongoDB</display-name>
<context-param>
<param-name>MONGO_HOST</param-name>
<param-value>localhost</param-value>
</context-param>
<context-param>
<param-name>MONGO_PORT</param-name>
<param-value>27017</param-value>
</context-param>
<welcome-file-list>
<welcome-file>users.jsp</welcome-file>
</welcome-file-list>
</web-app>
Consol output is bellow:
Kas 26, 2016 4:53:23 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:KullaniciYonetimSistemiMongoDB' did not find a matching property.
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.36
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jun 9 2016 13:55:50 UTC
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.36.0
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jre1.8.0_111
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_111-b14
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\javaTools\apache-tomcat-8.0.36
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\javaTools\apache-tomcat-8.0.36
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\javaTools\apache-tomcat-8.0.36
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\javaTools\apache-tomcat-8.0.36
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\javaTools\apache-tomcat-8.0.36\wtpwebapps
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\javaTools\apache-tomcat-8.0.36\endorsed
Kas 26, 2016 4:53:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1254
Kas 26, 2016 4:53:23 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: 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\jre1.8.0_111\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_111/bin/server;C:/Program Files/Java/jre1.8.0_111/bin;C:/Program Files/Java/jre1.8.0_111/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_101\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5\Doctrine extensions for PHP\;C:\Program Files\nodejs\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\Calibre2\;C:\Program Files (x86)\scala\bin;C:\Program Files\Java\jdk1.8.0_101\bin\;C:\Users\mypc\AppData\Roaming\npm;C:\adb; C:\maven\apache-maven-3.3.9\bin;C:\maven\apache-maven-3.3.9\bin;C:\Users\mypc\AppData\Roaming\npm;%M2%;C:\Program Files\MongoDB\Server\3.2\bin;;C:\Users\mypc\Downloads\programlar\eclipse;;.
Kas 26, 2016 4:53:24 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Kas 26, 2016 4:53:24 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Kas 26, 2016 4:53:24 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Kas 26, 2016 4:53:24 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Kas 26, 2016 4:53:24 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2248 ms
Kas 26, 2016 4:53:24 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Kas 26, 2016 4:53:24 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.36
Kas 26, 2016 4:53:26 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: 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.
Kas 26, 2016 4:53:26 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\docs
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\docs has finished in 35 ms
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\examples
Kas 26, 2016 4:53:27 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Kas 26, 2016 4:53:27 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\examples has finished in 586 ms
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\host-manager
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\host-manager has finished in 64 ms
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\manager
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\manager has finished in 58 ms
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\ROOT
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\javaTools\apache-tomcat-8.0.36\webapps\ROOT has finished in 33 ms
Kas 26, 2016 4:53:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Kas 26, 2016 4:53:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Kas 26, 2016 4:53:27 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2953 ms
Kas 26, 2016 4:53:28 PM com.mongodb.diagnostics.logging.JULLogger log
**INFO: Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket**
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:116)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 more
**Kas 26, 2016 4:53:37 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]}. Waiting for 30000 ms before timing out**
**Kas 26, 2016 4:54:07 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.fatih.controller.AddUser] in context with path [/KullaniciYonetimSistemiMongoDB] threw exception
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]**
at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:375)
at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:104)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:134)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:61)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:333)
at com.mongodb.DBCollection.insert(DBCollection.java:328)
at com.mongodb.DBCollection.insert(DBCollection.java:319)
at com.mongodb.DBCollection.insert(DBCollection.java:289)
at com.mongodb.DBCollection.insert(DBCollection.java:255)
at com.mongodb.DBCollection.insert(DBCollection.java:192)
at com.fatih.dao.UserDAO.createUser(UserDAO.java:23)
at com.fatih.controller.AddUser.doPost(AddUser.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
***IN WEB BROWSER:***
**HTTP Status 500 - Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]**
**type Exception report
message Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
description The server encountered an internal error that prevented it from fulfilling this request.
exception
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:375)
com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:104)
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68)
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221)
com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:134)
com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:61)
com.mongodb.Mongo.execute(Mongo.java:827)
com.mongodb.Mongo$2.execute(Mongo.java:810)
com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:333)
com.mongodb.DBCollection.insert(DBCollection.java:328)
com.mongodb.DBCollection.insert(DBCollection.java:319)
com.mongodb.DBCollection.insert(DBCollection.java:289)
com.mongodb.DBCollection.insert(DBCollection.java:255)
com.mongodb.DBCollection.insert(DBCollection.java:192)
com.fatih.dao.UserDAO.createUser(UserDAO.java:23)
com.fatih.controller.AddUser.doPost(AddUser.java:69)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.36 logs.**

I solve this problem;I change mongodb java driver version from 3.0.1 to 2.13.3 in pom.xml.Project run succesfully.

Related

Eclipse tomcat java.lang.ClassNotFoundException: com.web.servlets.SearchServiceServlet

Tomcat throws exception
java.lang.ClassNotFoundException: com.web.servlets.SearchServiceServlet every time i try to access my servlet.
The servlets is in the correct package structure:
I defined my servlet in the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>PetClinic</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<servlet>
<servlet-name>searchService</servlet-name>
<servlet-class>com.web.servlets.SearchServiceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>searchService</servlet-name>
<url-pattern>/searchServ</url-pattern>
</servlet-mapping>
</web-app>
The servlet class:
public class SearchServiceServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public SearchServiceServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");
int age = Integer.valueOf( request.getParameter("age") );
String pet_name = request.getParameter("pet_Name");
String pet_type = request.getParameter("pet_type");
int rating = Integer.valueOf(request.getParameter("rating"));
int experience = Integer.valueOf(request.getParameter("experience"));
System.out.println("First name = "+first_name+",last name = "+last_name+",age = "+age+",pet's name = "+pet_name+",pet's type = "+pet_type+",rating = "+rating+",experience = "+experience);
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
Could it be that eclipse doesn't properly generate classes?If yes,how can i test this?Because a simple POJO with main method works fine.
Also,here is the full exception and what the tomcat prints when i start the application:
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name: Apache Tomcat/9.0.17
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Mar 13 2019 15:55:27 UTC
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 9.0.17.0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 10
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jdk1.8.0_181\jre
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_181-b13
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\Barracuda\Desktop\Projects\Eclipse Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 9.0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\Barracuda\Desktop\Projects\Eclipse Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\Barracuda\Desktop\Projects\Eclipse Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 9.0\endorsed
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1251
апр 11, 2019 12:15:21 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: An older version [1.2.17] of the APR based Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [1.2.21]
апр 11, 2019 12:15:21 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Loaded APR based Apache Tomcat Native library [1.2.17] using APR version [1.6.3].
апр 11, 2019 12:15:21 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
апр 11, 2019 12:15:21 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
апр 11, 2019 12:15:22 PM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized [OpenSSL 1.0.2o 27 Mar 2018]
апр 11, 2019 12:15:22 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
апр 11, 2019 12:15:23 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
апр 11, 2019 12:15:23 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [2 666] milliseconds
апр 11, 2019 12:15:23 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
апр 11, 2019 12:15:23 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.17]
апр 11, 2019 12:15:23 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: 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.
апр 11, 2019 12:15:24 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: 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.
апр 11, 2019 12:15:24 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
апр 11, 2019 12:15:24 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
апр 11, 2019 12:15:24 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [987] milliseconds
апр 11, 2019 12:15:28 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet [searchService] as unavailable
апр 11, 2019 12:15:28 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet [searchService]
java.lang.ClassNotFoundException: com.web.servlets.SearchServiceServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1363)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1186)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1031)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:761)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
P.S The class is in the right package :package com.web.servlets;
Try specifying the package in your class file.
package com.web.servlets;
java.lang.ClassNotFoundException Exception is thrown when the ClassLoader cannot find the specified class.
You have:
<servlet-class>com.web.servlets.SearchServiceServlet</servlet-class>
That means you have a package: com.web.servlets where the class SearchServiceServlet is located.
In case you have a Maven project you should have scr/main/java/%yourpackagename%/yourClass
In case it is a simple web-project then it should be like src/yourpackagename/yourClass.
The problem got fixed after the restart of eclipse...Though there is another problem. Whenever i save the servlets class,after changing it,it doesn't see the new class,but uses the previous version of it.What's the problem here?

JAX-RS on TomCat always returns 404

I have already looked at many tutorials, but I can't get my simple JAX-RS application to work. Tomcat always returns Error 404.
The Application to get Classes:
package api;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/resources")
public class MyApplication extends Application {
// All request scoped resources and providers
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
classes.add(AuthenticationEndpoint.class);
return classes;
}
}
My JAX-RS file:
package api;
#Path("/hello")
public class AuthenticationEndpoint {
#GET
public Response getUser() {
return Response.status(200).entity("getUser is called").build();
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>MSM-Master</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
<url-pattern>/resources</url-pattern>
</servlet-mapping>
</web-app>
Under "Web Project Settings" my Context root is: "MSM-Master"
The url I tried to call was:
http://localhost:8080/MSM-Master/resources/hello/
Edit:
added Tomcat Console output:
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNUNG: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:MSM-Master' did not find a matching property.
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server version: Apache Tomcat/8.0.30
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server built: Dec 1 2015 22:30:46 UTC
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server number: 8.0.30.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Name: Windows 7
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Version: 6.1
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Architecture: amd64
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Java Home: C:\Program Files\Java\jre1.8.0_66
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Version: 1.8.0_66-b18
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Vendor: Oracle Corporation
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_BASE: C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 8.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.base=C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dwtp.deploy=C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 8.0\endorsed
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dfile.encoding=Cp1252
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMATION: 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\jre1.8.0_66\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre1.8.0_66/bin/server;C:/Program Files/Java/jre1.8.0_66/bin;C:/Program Files/Java/jre1.8.0_66/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Java\jdk1.8.0_66\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Users\u016975\AppData\Roaming\npm\;C:\Users\u016975\apache-ant-1.9.7\bin;C:\Users\u016975\AppData\Local\Android\android-sdk\tools;C:\Users\u016975\AppData\Local\Android\android-sdk\platform-tools;C:\windows\system32; C:\windows; C:\windows\System32\Wbem;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14\bin;C:\Users\u016975\AppData\Local\Apps\cURL\bin;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.15\bin;node_modules\npm;C:\Program Files\nodejs\;C:\Users\u016975\apache-ant-1.9.7\bin;C:\Users\u016975\AppData\Local\Android\android-sdk\tools;C:\Users\u016975\AppData\Local\Android\android-sdk\platform-tools;C:\windows\system32; C:\windows; C:\windows\System32\Wbem;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14\bin;C:\Users\u016975\AppData\Local\Apps\cURL\bin;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.15\bin;node_modules\npm;C:\Users\u016975\AppData\Roaming\npm;C:\Program Files\Microsoft VS Code\bin;C:\Users\u016975\Downloads\eclipse-jee-mars-1-win32-x86_64\eclipse;;.
Dez 14, 2017 4:32:39 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["http-nio-8080"]
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Dez 14, 2017 4:32:39 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["ajp-nio-8009"]
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.Catalina load
INFORMATION: Initialization processed in 621 ms
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.StandardService startInternal
INFORMATION: Starting service Catalina
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.StandardEngine startInternal
INFORMATION: Starting Servlet Engine: Apache Tomcat/8.0.30
Dez 14, 2017 4:32:46 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMATION: 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.
Dez 14, 2017 4:32:46 PM org.apache.catalina.core.StandardContext startInternal
SCHWERWIEGEND: Error during ServletContainerInitializer processing
javax.servlet.ServletException: java.lang.InstantiationException: org.glassfish.tyrus.server.TyrusServerConfiguration
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:88)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5244)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.InstantiationException: org.glassfish.tyrus.server.TyrusServerConfiguration
at java.lang.Class.newInstance(Unknown Source)
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:74)
... 8 more
Caused by: java.lang.NoSuchMethodException: org.glassfish.tyrus.server.TyrusServerConfiguration.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 10 more
Dez 14, 2017 4:32:46 PM org.apache.catalina.core.StandardContext startInternal
SCHWERWIEGEND: Context [/MSM-Master] startup failed due to previous errors
Dez 14, 2017 4:32:46 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["http-nio-8080"]
Dez 14, 2017 4:32:46 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["ajp-nio-8009"]
Dez 14, 2017 4:32:46 PM org.apache.catalina.startup.Catalina start
INFORMATION: Server startup in 6457 ms
#ApplicationPath provided by JAX – RS which is used to develop a restful web services application with out web.xml. So you can delete your web.xml
Then try overriding getProperties
#ApplicationPath("/resources")
public class MyApplication extends Application {
// All request scoped resources and providers
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
classes.add(AuthenticationEndpoint.class);
return classes;
}
#Override
public Map<String, Object> getProperties() {
final Map<String, Object> properties = new HashMap<>();
properties.put("jersey.config.server.provider.packages",
"api");//api-->here mention your yourpackage.to.scan"
return properties;
}
}

Error instantiating servlet class com.XYZClass

When I try to load servlet in my eclipse neon, it gives me "Error instantiating servlet class com.Test" error stating that "The server encountered an internal error that prevented it from fulfilling this request." I can load .jsp page successfully but while trying to load servlet page it gives me following error in eclipse borwser.
and console generates following error.
Sep 07, 2016 9:03:01 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Demo' did not find a matching property.
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/7.0.70
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jun 15 2016 16:27:45 UTC
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 7.0.70.0
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jre1.8.0_101
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_101-b13
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: D:\darshana\eWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 7.0
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=D:\darshana\eWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 7.0
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=D:\darshana\eWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 7.0\endorsed
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Sep 07, 2016 9:03:01 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: 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\jre1.8.0_101\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_101/bin/server;C:/Program Files/Java/jre1.8.0_101/bin;C:/Program Files/Java/jre1.8.0_101/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\nodejs\;C:\Program Files\MongoDB\Server\3.2\bin;C:\Users\darshana.ahalpara\AppData\Roaming\npm;C:\Program Files\MongoDB\Server\3.2\bin;C:\Program Files\Java\jdk1.8.0_101\bin;;C:\Users\darshana.ahalpara\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Eclipse;;.
Sep 07, 2016 9:03:01 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8085"]
Sep 07, 2016 9:03:01 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 731 ms
Sep 07, 2016 9:03:02 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 07, 2016 9:03:02 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.70
Sep 07, 2016 9:03:02 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8085"]
Sep 07, 2016 9:03:02 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 07, 2016 9:03:02 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 954 ms
Sep 07, 2016 9:03:27 AM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Demo as unavailable
Sep 07, 2016 9:03:27 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Demo
java.lang.ClassNotFoundException: com.Test
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1891)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1734)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:504)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:486)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:113)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1146)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:866)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Following is my directory structure.
here my Test.java
package com.abc;
import java.io.IOException;
import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Test
*/
//#WebServlet("/Test")
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public Test() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Hello....!!!!!! ");//.append(request.getContextPath());
}
}
Here is web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
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"
version="3.0">
<servlet>
<servlet-name>Demo</servlet-name>
<servlet-class>com.abc.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Demo</servlet-name>
<url-pattern>/demo</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>example</servlet-name>
<jsp-file>/exmpl.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>example</servlet-name>
<url-pattern>/example</url-pattern>
</servlet-mapping>
</web-app>

unable to run spring MVC fully annotation based

I'm new to Spring MVC. My project structure is as follows:
I'm getting the following error while running the web project:
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/7.0.65
AppConfig.java:
package config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
#Configuration
#EnableWebMvc
public class AppConfig {
#Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
AppInitializer.java:
package config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { AppConfig.class };
}
#Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
#Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
UserController.java:
package controller;
import model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import service.UserService;
#Controller
public class UserController {
#Autowired
private UserService userService;
#RequestMapping(value="/users",method= RequestMethod.GET)
public String listUsers(Model model) {
model.addAttribute("user",new User());
model.addAttribute("listUser" , userService.listUser());
return "user";
}
}
Startup logs:
Jul 13, 2016 12:14:24 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:demo' did not find a matching property.
Jul 13, 2016 12:14:24 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:test' did not find a matching property.
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/7.0.65
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Oct 9 2015 08:36:58 UTC
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 7.0.65.0
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jre1.8.0_72
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_72-b15
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: D:\bruno\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: D:\apache-tomcat-7.0.65\apache-tomcat-7.0.65
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=D:\bruno\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=D:\apache-tomcat-7.0.65\apache-tomcat-7.0.65
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=D:\bruno\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=D:\apache-tomcat-7.0.65\apache-tomcat-7.0.65\endorsed
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Jul 13, 2016 12:14:24 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: 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\jre1.8.0_72\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre1.8.0_72/bin/server;C:/Program Files/Java/jre1.8.0_72/bin;C:/Program Files/Java/jre1.8.0_72/lib/amd64;C:\oraclexe\app\oracle\product\11.2.0\server\bin;;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\Program Files (x86)\Microsoft Application Virtualization Client;C:\Program Files\TortoiseSVN\bin;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\Program Files (x86)\Microsoft Application Virtualization Client;C:\Program Files\TortoiseSVN\bin;C:\windows\System32\WindowsPowerShell\v1.0\;;D:\apache-ant-1.9.7-bin\apache-ant-1.9.7\bin;C:\Program Files\Java\jdk1.8.0_77\bin;C:\Users\kushagra_maurya\Desktop\ABC\eclipse-jee-juno-SR2-win32-x86_64\eclipse;;.
Jul 13, 2016 12:14:24 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8084"]
Jul 13, 2016 12:14:24 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8085"]
Jul 13, 2016 12:14:24 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1261 ms
Jul 13, 2016 12:14:24 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 13, 2016 12:14:24 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.65
Jul 13, 2016 12:14:25 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [134] milliseconds.
Jul 13, 2016 12:14:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8084"]
Jul 13, 2016 12:14:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8085"]
Jul 13, 2016 12:14:26 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1664 ms
What am I missing here? Any help will be appreciated.
I am pretty sure you are calling the root path of the server (e.g. localhost:8080/), right?
Eclipse deploys WebApplication in a context path with your projects name. The working path should be localhost:8080/<yourProjectName>/
You can change this behavior by opening the project settings -> Web Project Settings -> Context root.
Edit: since your only endpoint is /users you have to call localhost:8080/<yourProjectName>/users

Simple Web App using PostgreSQL and Tomcat

I'm trying to follow a tutorial to make a simple web application using PostgreSQL as db with Hibernate, Tomcat as server and Eclipse as IDE.
The user should enter name, surname and country to a simple form
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>My first Web App</title>
</head>
<body>
<h1>Let's create a new user</h1>
<form method="POST" action = "CreateUser.do">
First Name <input type = "text" size = "40" maxlength = "40" name = "firstname" /><br/>
Last Name <input type = "text" size = "40" maxlength = "40" name = "lastname" /><br/>
Country <input type = "text" size = "40" maxlength = "40" name = "country" /><br/>
<input type = "submit" value = "create" >
</form>
</body>
</html>
Then I have AddUser.java as Controller in the Model View Controller pattern
package controller;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import model.User;
/**
* Servlet implementation class AddUser
*/
#WebServlet(description = "Create new user Servlet", urlPatterns = {"/CreateUser.do"})
public class AddUser extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/*
RequestDispatcher view = request.getRequestDispatcher("useradd.jsp");
view.forward(request, response);
*/
Configuration config = new Configuration().configure();
ServiceRegistry servReg = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
SessionFactory factory = config.buildSessionFactory(servReg);
Session session = factory.openSession();
session.beginTransaction();
User u = new User(request.getParameter("firstname"),
request.getParameter("lastname"),
request.getParameter("country"));
session.save(u);
session.getTransaction().commit();
session.close();
RequestDispatcher view = request.getRequestDispatcher("useradd.jsp");
view.forward(request, response);
}
}
And User.java as Model
package model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table( name = "users")
public class User {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="user_id", nullable=false, unique=true)
private int id;
#Column(name="firstname", length=40, nullable=false)
private String firstname;
#Column(name="lastname", length=40, nullable=false)
private String lastname;
#Column(name="country", length=40, nullable=true)
private String country;
public User(String firstName, String lastName, String country) {
firstname = firstName;
lastname = lastName;
this.country = country;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstname;
}
public void setFirstName(String firstName) {
this.firstname = firstName;
}
public String getLastName() {
return lastname;
}
public void setLastName(String lastName) {
this.lastname = lastName;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
Lastly, useradd.jsp acts as view and should show the data written in the DB.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My first Web App - New User Created!</title>
</head>
<body>
<h1>New User Created</h1>
<p>
First Name: <% String fName = request.getParameter("firstname"); out.print(fName); %> <br/>
Last Name: <% String lName = request.getParameter("lastname"); out.print(lName); %> <br/>
Country: <% String country = request.getParameter("country"); out.print(country); %> <br/>
</p>
</body>
</html>
I've also made the hibernate.cfg.xml file in the /src folder
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/firstapp</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">admin</property>
<property name="show_sql">false</property>
<mapping class="model.User"/>
</session-factory>
</hibernate-configuration>
I can run the application, type in first name/last name/country but, when I press create, it shows this error: HTTP Status 500 - Unknown entity: model.User
Of course it doesn't write anything to the DB.
This is what the console shows:
mag 13, 2016 7:20:44 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:2 - Hibernate' did not find a matching property.
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server version: Apache Tomcat/8.0.33
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server built: Mar 18 2016 20:31:49 UTC
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Server number: 8.0.33.0
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: OS Name: Windows 10
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: OS Version: 10.0
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Architecture: x86
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Java Home: C:\Program Files (x86)\Java\jre1.8.0_91
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: JVM Version: 1.8.0_91-b14
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: JVM Vendor: Oracle Corporation
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: CATALINA_BASE: C:\Users\Antonio\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: CATALINA_HOME: C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dcatalina.base=C:\Users\Antonio\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dcatalina.home=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dwtp.deploy=C:\Users\Antonio\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Djava.endorsed.dirs=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\endorsed
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAZIONI: Command line argument: -Dfile.encoding=Cp1252
mag 13, 2016 7:20:44 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAZIONI: 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 (x86)\Java\jre1.8.0_91\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files (x86)/Java/jre1.8.0_91/bin/client;C:/Program Files (x86)/Java/jre1.8.0_91/bin;C:/Program Files (x86)/Java/jre1.8.0_91/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\Antonio\Desktop\eclipse;;.
mag 13, 2016 7:20:44 PM org.apache.coyote.AbstractProtocol init
INFORMAZIONI: Initializing ProtocolHandler ["http-nio-8080"]
mag 13, 2016 7:20:44 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAZIONI: Using a shared selector for servlet write/read
mag 13, 2016 7:20:44 PM org.apache.coyote.AbstractProtocol init
INFORMAZIONI: Initializing ProtocolHandler ["ajp-nio-8009"]
mag 13, 2016 7:20:44 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAZIONI: Using a shared selector for servlet write/read
mag 13, 2016 7:20:44 PM org.apache.catalina.startup.Catalina load
INFORMAZIONI: Initialization processed in 1448 ms
mag 13, 2016 7:20:44 PM org.apache.catalina.core.StandardService startInternal
INFORMAZIONI: Starting service Catalina
mag 13, 2016 7:20:44 PM org.apache.catalina.core.StandardEngine startInternal
INFORMAZIONI: Starting Servlet Engine: Apache Tomcat/8.0.33
mag 13, 2016 7:20:45 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFORMAZIONI: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [199] milliseconds.
mag 13, 2016 7:20:46 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMAZIONI: 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.
mag 13, 2016 7:20:46 PM org.apache.coyote.AbstractProtocol start
INFORMAZIONI: Starting ProtocolHandler ["http-nio-8080"]
mag 13, 2016 7:20:46 PM org.apache.coyote.AbstractProtocol start
INFORMAZIONI: Starting ProtocolHandler ["ajp-nio-8009"]
mag 13, 2016 7:20:46 PM org.apache.catalina.startup.Catalina start
INFORMAZIONI: Server startup in 1935 ms
mag 13, 2016 7:21:06 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.1.0.Final}
mag 13, 2016 7:21:06 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
mag 13, 2016 7:21:06 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
mag 13, 2016 7:21:07 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
mag 13, 2016 7:21:08 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
mag 13, 2016 7:21:08 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/firstapp]
mag 13, 2016 7:21:08 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=postgres, password=****}
mag 13, 2016 7:21:08 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
mag 13, 2016 7:21:08 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
mag 13, 2016 7:21:08 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
mag 13, 2016 7:21:09 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
mag 13, 2016 7:21:09 PM org.hibernate.type.BasicTypeRegistry register
INFO: HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType#bfbdad
mag 13, 2016 7:21:10 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [controller.AddUser] in context with path [/2_-_Hibernate] threw exception
org.hibernate.MappingException: Unknown entity: model.User
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1533)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:682)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:674)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:669)
at controller.AddUser.doPost(AddUser.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
I've been stuck for hours and cannot find any solution.
Hope you guys can help me. Thanks in advance!
If you are using Hiberanate 5, please create Session factory in this way:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
instead of
Configuration config = new Configuration().configure();
ServiceRegistry servReg = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
SessionFactory factory = config.buildSessionFactory(servReg);

Categories

Resources