Я нашел несколько вопросов с одинаковой проблемой, за исключением того факта, что я использую встроенный tomcat.Нет WebApplicationContext не найден в запросе DispatcherServlet и не зарегистрирован ContextLoaderListener
Я пробовал все ответы, которые я нашел, большинство из них связано с ContextLoaderListener и зависимостями.
Я заметил, что когда я создал приложение после «mvn clean package», есть несколько предупреждений о дублировании, но, честно говоря, я не думаю, что это проблема. Я считаю, что есть некоторая проблема между встроенной конфигурацией Tomcat и контекстом.
бревен во время Buiding
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
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Spring MVC Application</display-name>
<!-- I tried add COntextLoader Listener and explicitly point to App-servlet.xml but I don~t think it is necessary
By the way, same error with it or without -->
<!-- listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/App-servlet.xml</param-value>
</context-param -->
<servlet>
<servlet-name>App</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>App</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
статических главного
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 Word, он будет работать в качестве Wellcome страницы)
<%@ 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-ю строку, которая обозначает «». Я думаю, что App-servlet.xml не учитывается. Пожалуйста, посмотрите структуру папок и основной метод и дайте мне знать, если вы думаете, что я что-то упускаю. –