2015-10-19 3 views
0

Я разрабатываю веб-приложение на основе Spring, и я пытаюсь использовать плитки apache 3. Однако, хотя я думаю, что у меня есть все необходимые зависимости и настройки файлов, я постоянно получить сообщение об ошибке, связанное с тем, что класс запроса контекста приложения не найден.Проблема с использованием плиток apache 3 в веб-проекте весны mvc

Кто-нибудь видит, что я делаю неправильно?

Это мой pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.phoebus</groupId> 
    <artifactId>spittr</artifactId> 
    <name>SpringMVCTest</name> 
    <packaging>war</packaging> 
    <version>1.0.0-BUILD-SNAPSHOT</version> 
    <properties> 
     <java-version>1.8</java-version> 
     <org.springframework-version>3.2.2.RELEASE</org.springframework-version> 
     <org.aspectj-version>1.6.10</org.aspectj-version> 
     <org.slf4j-version>1.6.6</org.slf4j-version> 
    </properties> 
    <dependencies> 
     <!-- Spring --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>4.2.1.RELEASE</version> 
      <exclusions> 
       <!-- Exclude Commons Logging in favor of SLF4j --> 
       <exclusion> 
        <groupId>commons-logging</groupId> 
        <artifactId>commons-logging</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>4.2.1.RELEASE</version> 
     </dependency> 

     <!-- AspectJ --> 
     <dependency> 
      <groupId>org.aspectj</groupId> 
      <artifactId>aspectjrt</artifactId> 
      <version>${org.aspectj-version}</version> 
     </dependency> 

     <!-- Logging --> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>${org.slf4j-version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>jcl-over-slf4j</artifactId> 
      <version>${org.slf4j-version}</version> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>${org.slf4j-version}</version> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.15</version> 
      <exclusions> 
       <exclusion> 
        <groupId>javax.mail</groupId> 
        <artifactId>mail</artifactId> 
       </exclusion> 
       <exclusion> 
        <groupId>javax.jms</groupId> 
        <artifactId>jms</artifactId> 
       </exclusion> 
       <exclusion> 
        <groupId>com.sun.jdmk</groupId> 
        <artifactId>jmxtools</artifactId> 
       </exclusion> 
       <exclusion> 
        <groupId>com.sun.jmx</groupId> 
        <artifactId>jmxri</artifactId> 
       </exclusion> 
      </exclusions> 
      <scope>runtime</scope> 
     </dependency> 

     <!-- @Inject --> 
     <dependency> 
      <groupId>javax.inject</groupId> 
      <artifactId>javax.inject</artifactId> 
      <version>1</version> 
     </dependency> 

     <!-- Servlet --> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>servlet-api</artifactId> 
      <version>3.0-alpha-1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet.jsp</groupId> 
      <artifactId>jsp-api</artifactId> 
      <version>2.2.1-b03</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.2</version> 
     </dependency> 

     <!-- Test --> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.7</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>javax.validation</groupId> 
      <artifactId>validation-api</artifactId> 
      <version>1.1.0.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-validator</artifactId> 
      <version>5.0.1.Final</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>javax.servlet-api</artifactId> 
      <version>4.0.0-b01</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>4.2.1.RELEASE</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-extras</artifactId> 
      <version>3.0.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-servlet</artifactId> 
      <version>3.0.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-jsp</artifactId> 
      <version>3.0.5</version> 
     </dependency> 

     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-jdk14</artifactId> 
      <version>1.7.12</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-core</artifactId> 
      <version>3.0.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-api</artifactId> 
      <version>3.0.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-compat</artifactId> 
      <version>3.0.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-request-api</artifactId> 
      <version>1.0.6</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-digester</groupId> 
      <artifactId>commons-digester</artifactId> 
      <version>2.1</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-beanutils</groupId> 
      <artifactId>commons-beanutils</artifactId> 
      <version>1.9.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-template</artifactId> 
      <version>3.0.5</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-eclipse-plugin</artifactId> 
       <version>2.9</version> 
       <configuration> 
        <additionalProjectnatures> 
         <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> 
        </additionalProjectnatures> 
        <additionalBuildcommands> 
         <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> 
        </additionalBuildcommands> 
        <downloadSources>true</downloadSources> 
        <downloadJavadocs>true</downloadJavadocs> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <compilerArgument>-Xlint:all</compilerArgument> 
        <showWarnings>true</showWarnings> 
        <showDeprecation>true</showDeprecation> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <configuration> 
        <mainClass>org.test.int1.Main</mainClass> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

Это мой сервлет контекст файла:

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     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"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <annotation-driven /> 

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

    <context:component-scan base-package="com.phoebus.spittr" /> 

    <!-- apache tiles --> 
    <beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> 
     <beans:property name="definitions"> 
      <beans:list> 
       <beans:value>/WEB-INF/layout/tiles.xml</beans:value> 
       <beans:value>/WEB-INF/views/**/tiles.xml</beans:value> 
      </beans:list> 
     </beans:property> 
    </beans:bean>  
    <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver" /> 

</beans:beans> 

Мой tiles.xml:

<?xml version="1.0" encoding="UTF-8"?> 

<!DOCTYPE tiles-definitions PUBLIC 
    "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" 
    "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"> 

<tiles-definitions> 

    <!-- base tile --> 
    <definition name="base" template="/WEB-INF/layout/page.jsp"> 
     <put-attribute name="header" value="/WEB-INF/layout/header.jsp" /> 
     <put-attribute name="footer" value="/WEB-INF/layout/footer.jsp" /> 
    </definition> 

    <!-- extensions to base tile --> 
    <definition name="home" extends="base"> 
     <put-attribute name="body" value="/WEB-INF/views/home.jsp"></put-attribute> 
    </definition> 

    <definition name="registerForm" extends="base"> 
     <put-attribute name="body" value="/WEB-INF/views/registerForm.jsp"></put-attribute> 
    </definition> 

    <definition name="profile" extends="base"> 
     <put-attribute name="body" value="/WEB-INF/views/profile.jsp"></put-attribute> 
    </definition> 

    <definition name="spittles" extends="base"> 
     <put-attribute name="body" value="/WEB-INF/views/spittles.jsp"></put-attribute> 
    </definition> 

    <definition name="spitter" extends="base"> 
     <put-attribute name="body" value="/WEB-INF/views/spitter.jsp"></put-attribute> 
    </definition> 

    <definition name="spittleView" extends="base"> 
     <put-attribute name="body" value="/WEB-INF/views/spittleView.jsp"></put-attribute> 
    </definition> 

</tiles-definitions> 

мой page.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="t" %> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Spittr</title> 
<link rel="stylesheet" type="text/css" href='<c:url value="/resources/style.css"/>'> 
</head> 
<body> 
    <div id="header"> 
     <t:insertAttribute name="header" /> 
    </div> 
    <div id="body"> 
     <t:insertAttribute name="body" /> 
    </div> 
    <div id="footer"> 
     <t:insertAttribute name="heafooterder" /> 
    </div> 
</body> 
</html> 

И исключение, которое брошено:

SEVERE: Allocate exception for servlet appServlet 
java.lang.ClassNotFoundException: org.apache.tiles.request.ApplicationContext 
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) 
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) 
    at java.lang.Class.getDeclaredMethods0(Native Method) 
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2693) 
    at java.lang.Class.getDeclaredMethods(Class.java:1967) 
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:606) 
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:518) 
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:504) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667) 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633) 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681) 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552) 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493) 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:158) 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231) 
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144) 
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    at java.lang.Thread.run(Thread.java:745) 

Я надеюсь, что вставили все соответствующие фрагменты кода.

Заранее благодарен!

ответ

1

Проблема в нижнем колонтитуле, она должна быть одинаковой. В вашем tiles.xml

<definition name="base" template="/WEB-INF/layout/page.jsp"> 
    <put-attribute name="header" value="/WEB-INF/layout/header.jsp" /> 
    <put-attribute name="footer" value="/WEB-INF/layout/footer.jsp" /> 
</definition> 

И ваш page.jsp

<div id="footer"> 
    <t:insertAttribute name="heafooterder" /> 
</div> 

Тогда имя тега "т: insertAttribute" heafooterder не совпадает с именем "пут-атрибута" , Решение состоит в том, чтобы переименовать heafooterder в footer в tiles.xml.

<div id="footer"> 
    <t:insertAttribute name="footer" /> 
</div> 

PD: Я думаю, что подмигнули с чего прийти зависимость плитки-статистов.

<dependency> 
    <groupId>org.apache.tiles</groupId> 
    <artifactId>tiles-extras</artifactId> 
    <version>3.0.5</version> 
</dependency> 

 Смежные вопросы

  • Нет связанных вопросов^_^