我发现了几个问题,除了我使用的是嵌入式tomcat之外,其他问题都是相同的。没有发现WebApplicationContext没有在DispatcherServlet中请求,也没有ContextLoaderListener注册
我尝试了所有我找到的答案,其中大部分与ContextLoaderListener和依赖关系有关。
我注意到,当我在“mvn clean package”之后构建应用程序时,有几个关于重复的警告,但是老实说我不认为这是问题。我相信在嵌入式Tomcat配置和上下文之间存在一些问题。层楼高
C:\STS\wsRestTemplate\TestDeployment>mvn clean package
...
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ TestDeployment ---
[INFO] Building jar: C:\STS\wsRestTemplate\TestDeployment\target\embeddedApp.jar
[INFO]
[INFO] --- appassembler-maven-plugin:1.10:assemble (default) @ TestDeployment --
-
[WARNING] The usage of program name (App) is deprecated. Please use program.id i
nstead.
[INFO] Installing artifact C:\Users\e049447\.m2\repository\org\springframework\s
pring-web\4.2.5.RELEASE\spring-web-4.2.5.RELEASE.jar to C:\STS\wsRestTemplate\Te
stDeployment\target\repo\org\springframework\spring-web\4.2.5.RELEASE\spring-web
-4.2.5.RELEASE.jar
[INFO] Installing artifact C:\Users\e049447\.m2\repository\org\springframework\s
pring-aop\4.2.5.RELEASE\spring-aop-4.2.5.RELEASE.jar to C:\STS\wsRestTemplate\Te
stDeployment\target\repo\org\springframework\spring-aop\4.2.5.RELEASE\spring-aop
-4.2.5.RELEASE.jar
...
[INFO] Installing artifact C:\STS\wsRestTemplate\TestDeployment\target\embeddedA
pp.jar to C:\STS\wsRestTemplate\TestDeployment\target\repo\com\mastercard\ictt\b
atchs\TestDeployment\0.0.1-SNAPSHOT\TestDeployment-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:1.3.3:shade (default) @ TestDeployment ---
[INFO] Including org.springframework:spring-web:jar:4.2.5.RELEASE in the shaded
jar.
[INFO] Including org.springframework:spring-aop:jar:4.2.5.RELEASE in the shaded
...[INFO] Including commons-io:commons-io:jar:2.2 in the shaded jar.
[INFO] Including javax.servlet:javax.servlet-api:jar:3.0.1 in the shaded jar.
[WARNING] We have a duplicate org/apache/jasper/Constants.class in C:\Users\e049
447\.m2\repository\org\apache\tomcat\tomcat-jasper\8.0.32\tomcat-jasper-8.0.32.j
ar
[WARNING] We have a duplicate org/apache/jasper/EmbeddedServletOptions.class in
C:\Users\e049447\.m2\repository\org\apache\tomcat\tomcat-jasper\8.0.32\tomcat-ja
sper-8.0.32.jar
[WARNING] We have a duplicate org/apache/jasper/JasperException.class in C:\User
s\e049447\.m2\repository\org\apache\tomcat\tomcat-jasper\8.0.32\tomcat-jasper-8.
0.32.jar
[WARNING] We have a duplicate org/apache/jasper/JspC.class in C:\Users\e049447\.
m2\repository\org\apache\tomcat\tomcat-jasper\8.0.32\tomcat-jasper-8.0.32.jar
[WARNING] We have a duplicate org/apache/jasper/JspCompilationContext.class in C
:\Users\e049447\.m2\repository\org\apache\tomcat\tomcat-jasper\8.0.32\tomcat-jas
per-8.0.32.jar
的App-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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="com.mycomp.myapp.batchs.AuthFileUpload" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
</beans>
的web.xml
012期间日志
静态主
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
public class App
{
public static void main(String[] args) throws LifecycleException
{
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir("C\\temp");
tomcat.addWebapp(tomcat.getHost(), "/", "C:\\temp\\");//
tomcat.start();
tomcat.getServer().await();
}
}
的index.jsp(如果我的评论下面的所有线条和我添加了一个简单的Hello字串,将工作作为惠康页)
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<body>
<h2>Uploading a file.. </h2>
<form:form method="POST" action="uploadFile" enctype="multipart/form-data">
Upload your file please:
<input type="file" name="file" />
<input type="text" name="name">
<input type="submit" value="Upload" />
<form:errors path="file" cssStyle="color: #ff0000;" />
</form:form>
</body>
</html>
控制器
@Controller
public class FileUploadController {
@RequestMapping(value="/upload",method = RequestMethod.GET)
public String printHello(ModelMap model) {
return "index";
}
我做到了,它保持同样的错误。请注意,第7行代表“