私はSpring MVCアプリケーションの簡単な例を持っています。 gradle configにはspringmvcとjstlの2つの依存関係しかありません。これらの依存関係は、WARファイルのWEB-INF/libフォルダに含まれています。しかし、Tomcatでは、ターゲットページを取得しようとするとClassNotFoundExceptionが発生します。Spring MVC JSTL Config ClassNotFoundException
Tomcatバージョン - 8.5.16
プロジェクト構造:
src/main/java/net/wls/test/springmvc/HelloController.java
src/main/webapp/WEB-INF/jsp/hello.jsp
src/main/webapp/WEB-INF/servlet-context.xml
src/main/webapp/WEB-INF/web.xml
src/main/webapp/index.html
build.gradle
HelloController.java:
package net.wls.test.springmvc;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController {
@RequestMapping("/hello")
public ModelAndView hello() {
String message = "Hello World!";
return new ModelAndView("hello", "message", message);
}
}
Hello.jspの:
<h1>${message}</h1>
サーブレット・コンテキスト。 xml:
<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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="net.wls.test"/>
<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>
</beans>
のweb.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.1">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet-context.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
build.gradle:
group 'net.wls.test'
version '0.1.0'
def springVersion = '5.0.0.RELEASE'
apply plugin: 'war'
sourceCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
task copyRuntimeLibs(type: Copy) {
into 'lib'
from configurations.runtime
}
war {
classpath fileTree('lib')
}
dependencies {
compile group: 'org.springframework', name: 'spring-webmvc', version: "$springVersion"
compile group: 'javax.servlet.jsp.jstl', name: 'jstl', version: '1.2'
}
私は例外スタックトレースを添付するのを忘れ: ます。java.lang.NoClassDefFoundError:javaxの/サーブレット/ JSP/JSTL /コア/コンフィグ \t org.springframework.web.servlet.support.JstlUtils.exposeLocalizationContext(JstlUtils.java: 102) –