我在一个Java动态Web项目中使用了Spring,它在Windows上运行良好,但在我将它部署到Ubuntu VM后,控制器无法工作,我还在Eclipse Windows上创建了一个.war文件并通过tomcat manager部署它但没有奏效。
然后我只是将我的src代码复制到webapps文件夹,但是它似乎只显示.jsp页面,它没有将页面映射到@requestMapping并调用控制器类,我是否需要进行任何设置在Linux上配置/使其工作?
打开应用程序后,index.jsp显示内容,但点击提交后,它应该通过<form class="formcolor" action="tiers" method="GET">
调用AppDynamicsMain.java控制器,而是寻找要显示的层页面并抛出HTTP状态404 - 找不到:
我在$ CATALINA_HOME / webapps / appd-cp / WebContent / WEB-INF / lib /下有所有必需的jar文件,我是否需要移动它们$ CATALINA_HOME / lib /?
非常感谢您的帮助。
P.S:我的虚拟机没有GUI,只能通过终端访问(使用mobaXterm ssh到ip)
我必须在项目的根目录下创建一个额外的index.jsp来调用项目jsp文件夹中的index.jsp:$ CATALINA_HOME / webapps / appd-cp / index.jsp:
<html>
<head>
<META http-equiv="refresh" content="0;URL=WebContent/WEB-INF/jsp/index.jsp">
</head>
<body>
</body>
</html>
WebContent / WEB-INF / jsp / index.jsp中的index.jsp:
<html>
<head>
<META http-equiv="refresh" content="0;URL=welcome.jsp">
</head>
<body>
</body>
</html>
这是我在VM中的项目结构:
appd-cp
|->index.jsp
|->src
| -->com.sh
| --->AppDynamicsMain.java
|->WebContent
| -->WEB-INF
| --->jsp
| ---->index.jsp
| ---->rawDataCPU.jsp
| ---->graphCPU.jsp
| --->CapacityPlanning-servlet.xml
| --->web.xml
的welcome.jsp:
<html>
<head>
<title>my title</title>
</head>
<style type="text/css">
<%@include file="site.css" %>
</style>
<body>
<div id="flip-tabs" >
<ul id="flip-navigation" >
<li><a href="welcome.jsp" id="tab-0">Graph</a></li>  
<li class="selected"><a href="welcomeRawData.jsp" id="tab-1" >Raw Data</a></li>  
<li><a href="#" id="tab-2" >Subscribe</a></li>  
</ul>
</div>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
}
</script>
<BR><BR><div style="margin-left: 70px;"><p>select the application, parameter and the duration:</p></div>
<form class="formcolor" action="tiers" method="GET">
<label>Application: </label>
<select name="application">
<option name="application" value="ALEXA_SKILL">ALEXA_SKILL</option>
<option name="application" value="AMP">AMP</option>
</select>
<BR>
<BR>
<label>Parameter: </label>
<select name="param">
<option name="param" value="CPU">CPU usage</option>
</select>
<BR>
<BR>
<label>Duration: </label>
<select name="duration">
<option name="duration" value="5">5 min</option>
<option name="duration" value="15">15 min</option>
<option name="duration" value="30">30 min</option>
</select>
<BR>
<BR>
<BR>
<progress id="p1" max="100" value="0"><span>0</span>%</progress>
<input type="submit" value="Submit"></input>
<form>
</body>
</html>
AppDynamicsMain.java:
package com.sh;
import java.io.File;
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.sh.PropertyFileReader;
@Controller
public class AppDynamicsMain {
protected static final String USERNAME = PropertyFileReader.getAppdUsername();
protected static final String PASSWORD = PropertyFileReader.getAppdPassword();
String DestPath = "/root/AppDynamics/";
public String fileName;
public String application;
static Log log = LogFactory.getLog(AppDynamicsMain.class.getName());
private Logger logger = Logger.getLogger(AppDynamicsMain.class);
static String downloadDestPath = "/root/AppDynamics/download/";
@RequestMapping(value = "tiers" , method = RequestMethod.GET)
public String getContent(@RequestParam(required = true) String application , @RequestParam(required = true) String param, @RequestParam(required = true) String duration, ModelMap model ) throws IOException{
logger.info("################### going to call rawData"+ param+ " . . . " );
File checkFolder = new File(downloadDestPath);
if(checkFolder.isDirectory()){
if(checkFolder.list().length>0){
FileUtils.cleanDirectory(checkFolder);
}
}
model.addAttribute(application , application);
model.addAttribute(duration , duration);
return "forward:/rawData"+param;
}
@RequestMapping(value = "graphs" , method = RequestMethod.GET)
public String getGraphContent(@RequestParam(required = true) String application , @RequestParam(required = true) String param , ModelMap model ){
logger.info("################### going to call get"+ param+ " . . . " );
model.addAttribute(application , application);
return "forward:/graph"+param;
}
}
的web.xml:
<web-app id = "WebApp_ID" version = "2.4"
xmlns = "http://java.sun.com/xml/ns/j2ee"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Capacity Forecasting - Planning</display-name>
<servlet>
<servlet-name>CapacityPlanning</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CapacityPlanning</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>MONGODB_HOST</param-name>
<param-value>localhost</param-value>
</context-param>
<context-param>
<param-name>MONGODB_PORT</param-name>
<param-value>27017</param-value>
</context-param>
CapacityPlanning-servlet.xml中:
<?xml version = "1.0" encoding = "UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation = "http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<context:component-scan base-package = "com.sh" />
<bean id = "viewResolver"
class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/WEB-INF/jsp/" />
<property name = "suffix" value = ".jsp" />
</bean>
<mvc:annotation-driven/>
</beans>
答案 0 :(得分:1)
问题是使用重复的jar文件。这些spring jar文件在WEB-INF / lib /:
中spring-web-3.0.1.RELEASE.jar
org.springframework.asm-3.1.0.RELEASE.jar
org.springframework.beans-3.1.0.RELEASE.jar
org.springframework.context-3.1.0.RELEASE.jar
org.springframework.core-3.1.0.RELEASE.jar
org.springframework.expression-3.1.0.release.jar
org.springframework.web-3.1.0.RELEASE.jar
org.springframework.web.servlet-3.1.0.RELEASE.jar
。,错误的根本原因是java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.consumes()
,其中org.springframework.web.bind.annotation.RequestMapping.class
是spring-web-3.0.1.RELEASE.jar
和org.springframework.web.servlet-3.1.0.RELEASE.jar
中的一个类,导致初始化失败。删除spring-web-3.0.1.RELEASE.jar
解决了问题,应用初始化就好了。
INFO 2017-09-20 21:50:00,252 [localhost-startStop-2] org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3917dc5c: defining beans [welcomeController,appTiersHeapMemoryUsed,webController,downloadController,modelController,appTiersMemoryUsage,appDynamicsMain,appTiersCPU,appTiersCurrentHeapMemoryUsage,appTiersTotalMemory,homeController,staticController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,viewResolver,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
INFO 2017-09-20 21:50:00,351 [localhost-startStop-2] org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3917dc5c: defining beans [welcomeController,appTiersHeapMemoryUsed,webController,downloadController,modelController,appTiersMemoryUsage,appDynamicsMain,appTiersCPU,appTiersCurrentHeapMemoryUsage,appTiersTotalMemory,homeController,staticController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,viewResolver,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
ERROR 2017-09-20 21:50:00,352 [localhost-startStop-2] org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.consumes()[Ljava/lang/String;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4931)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5241)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:988)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1860)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.consumes()[Ljava/lang/String;
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.createRequestMappingInfo(RequestMappingHandlerMapping.java:149)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.getMappingForMethod(RequestMappingHandlerMapping.java:105)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.getMappingForMethod(RequestMappingHandlerMapping.java:1)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$1.matches(AbstractHandlerMethodMapping.java:139)
at org.springframework.web.method.HandlerMethodSelector$1.doWith(HandlerMethodSelector.java:62)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:473)
at org.springframework.web.method.HandlerMethodSelector.selectMethods(HandlerMethodSelector.java:58)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:137)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:107)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initApplicationContext(AbstractHandlerMethodMapping.java:87)
at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:71)
at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 31 more