Spring MVC и Spring Data MongoDB приложение, дающее 404 страницы не найдено

99
11

Я запускаю Spring MVC и Spring Data MongoDB. Я успешно получаю приветственную страницу, указанную в web.xml. Но после того, как вы делаете ajax-вызовы на домашней странице или вызываете страницы jsp в папке WEB-INF/jsp, я получаю ошибку 404. Я видел несколько решений в stackoverflow и пытался манипулировать url-образцом, но это не сработало. Следующий URL-адрес успешно отображает страницу приветствия

http://localhost:8080/Hello-Platform/

Я ожидаю, что при нажатии на кнопку на моем экране приветствия (которое является home.jsp) будет вызываться url: "${pageContext.request.contextPath}/welcome",. Но я получаю GET http://localhost:8080/BDI-Platform/welcome 404 (Not Found)

Вызов ajax в home.jsp

        <script type="text/javascript">
$(document).ready(function(){
$("#client-register-form").submit(function(event) {
event.preventDefault();
registerClient();
});
});

function registerClient() {
$.ajax({
type : "GET",
url : "${pageContext.request.contextPath}/welcome",
timeout : 100000,
success : function(data) {
console.log("SUCCESS: ", data);
display(data);
},
error : function(e) {
alert(e);
console.log("ERROR: ", e);
},
done : function(e) {
console.log("DONE");
}
});
}

</script>

Мой 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>Hello-Platform</display-name>
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/home.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>hellop</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hellop</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<!--Root web application context-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/hello-servlet.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

Hello-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">

<context:component-scan base-package="com.hello.platform.controller.*" />
<context:component-scan base-package="com.hello.platform.mongo.repositories" />

<!-- Factory bean that creates the Mongo instance -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
<property name="host" value="localhost" />
</bean>
<!-- MongoTemplate for connecting and querying the documents in the database -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongo" ref="mongo" />
<constructor-arg name="databaseName" value="hellodatabase" />
</bean>

<!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

<mongo:repositories base-package="com.bdi.platform.mongo.repositories" />

<mvc:resources mapping="/resources/**" location="/resources/" />

<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

<mvc:annotation-driven />
</beans>

Класс контроллера

@Controller
public class HelloController {

@Autowired
private ClientInfoRepository clientInfoRepository;

@RequestMapping(value="/welcome")
public String helloWorld() {
System.out.println("Hello");
String message = "success";
return message;
}
}

Ошибка в журнале консоли Eclipse

 May 02, 2016 11:35:05 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Hello-Platform' did not find a matching property.
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.32
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Feb 2 2016 19:34:53 UTC
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.32.0
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Linux
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 3.13.0-67-generic
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: /usr/lib/jvm/java-7-openjdk-amd64/jre
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.7.0_95-b00
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /home/pankaj/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /opt/tomcat
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/home/pankaj/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/opt/tomcat
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/home/pankaj/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/opt/tomcat/endorsed
May 02, 2016 11:35:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
May 02, 2016 11:35:05 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: /usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
May 02, 2016 11:35:05 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
May 02, 2016 11:35:06 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
May 02, 2016 11:35:06 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
May 02, 2016 11:35:06 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
May 02, 2016 11:35:06 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 925 ms
May 02, 2016 11:35:06 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 02, 2016 11:35:06 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.32
May 02, 2016 11:35:08 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.
May 02, 2016 11:35:08 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
May 02, 2016 11:35:08 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
May 02, 2016 11:35:09 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=50}
May 02, 2016 11:35:09 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:1, serverValue:37}] to localhost:27017
May 02, 2016 11:35:09 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[2, 6, 12]}, minWireVersion=0, maxWireVersion=2, maxDocumentSize=16777216, roundTripTimeNanos=952004}
May 02, 2016 11:35:10 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'Hellop'
May 02, 2016 11:35:11 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=50}
May 02, 2016 11:35:11 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:2, serverValue:38}] to localhost:27017
May 02, 2016 11:35:11 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[2, 6, 12]}, minWireVersion=0, maxWireVersion=2, maxDocumentSize=16777216, roundTripTimeNanos=714168}
May 02, 2016 11:35:11 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
May 02, 2016 11:35:11 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
May 02, 2016 11:35:11 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5296 ms

Но браузер не может загрузить страницу с сервера

    GET http://localhost:8080/Hello-Platform/welcome 404 (Not Found)

Прямой вызов home.jsp url

http://localhost:8080/BDI-Platform/home.jsp

HTTP Status 404 - /Hello-Platform/home.jsp
type Status report
message /Hello-Platform/home.jsp
description The requested resource is not available.

спросил(а) 2016-05-03T06:54:00+03:00 4 года, 5 месяцев назад
0
Ваш ответ
Введите минимум 50 символов
Чтобы , пожалуйста,
Выберите тему жалобы:

Другая проблема