Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring MVC+;Freemarker集成404错误_Java_Spring_Maven_Spring Mvc_Freemarker - Fatal编程技术网

Java Spring MVC+;Freemarker集成404错误

Java Spring MVC+;Freemarker集成404错误,java,spring,maven,spring-mvc,freemarker,Java,Spring,Maven,Spring Mvc,Freemarker,我在将freemarker与spring集成时遇到了一个问题。我已经尽我所能地寻找了,现在只是感到困惑 我现在得到的错误是项目部署后的404错误 我希望有人能指出我哪里出了问题,为什么欢迎文件页面都没有加载 这是我的项目结构 +freemaerker-project +idea +src +main +java +controllers/entity +resources +webapp + WEB-I

我在将freemarker与spring集成时遇到了一个问题。我已经尽我所能地寻找了,现在只是感到困惑

我现在得到的错误是项目部署后的404错误

我希望有人能指出我哪里出了问题,为什么欢迎文件页面都没有加载

这是我的项目结构

+freemaerker-project
  +idea 
  +src
    +main 
      +java
        +controllers/entity
      +resources   
      +webapp
        + WEB-INF 
          + freemarker
            + ftl templates
        +web.xml
        +spring-servlet.xml
+pom
POM:


4.0.0
com.freemarker
自由标记弹簧
1.0-快照
org.springframework
spring上下文
4.1.4.1发布
org.springframework
spring上下文支持
3.2.4.1发布
org.springframework
弹簧网
4.1.6.1发布
org.springframework
SpringWebMVC
4.1.6.1发布
org.freemarker
自由标记
2.3.23
org.apache.maven.plugins
maven编译器插件
3.1
1.7
1.7
org.apache.maven.plugins
maven战争插件
2.3
假的
org.apache.maven.plugins
maven依赖插件
2.6
验证
复制
真的
爪哇
javaee认可的api
7
罐子

WEB.xml:

 <?xml version="1.0" encoding="UTF-8" ?>
 <web-app 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"
     version="2.4">

<display-name>Spring Web MVC Application</display-name>

<servlet>
    <servlet-name>spring-servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring-servlet</servlet-name>
    <url-pattern>/home</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>HomeController</servlet-name>
    <servlet-class>com.freemarker.controllers.HomeController</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>HomeController</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>src/WEB-INF/spring-servlet.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<welcome-file-list>
    <welcome-file>home.html</welcome-file>
    <welcome-file>home.ftl</welcome-file>
</welcome-file-list>

SpringWebMVC应用程序
SpringServlet
org.springframework.web.servlet.DispatcherServlet
1.
SpringServlet
/家
家庭控制器
com.freemarker.controllers.HomeController
1.
家庭控制器
/
上下文配置位置
src/WEB-INF/spring-servlet.xml
org.springframework.web.context.ContextLoaderListener
home.html
home.ftl

Spring-Servlet.xml

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

    <!-- freemarker config -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="src/WEB-INF/freemarker"/>
    <property name="preferFileSystemAccess" value="false" />
</bean>

<!-- View resolvers  -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <property name="cache" value="true"/>
    <property name="prefix" value=""/>
    <property name="suffix" value=".ftl"/>
</bean>


您试图访问的url是什么,您得到的是404?您还可以发布应用程序/服务器日志吗?是否打印了任何异常?在项目部署并在浏览器中打开后,我得到的只是“HTTP状态404-/Resource not available”,并且Tomcat日志中都没有错误。
src/WEB-INF/freemarker
看起来可疑。。。也许
/WEB-INF/freemarker
?同样
src/WEB-INF/spring servlet.xml
应该是
/WEB-INF/spring servlet.xml
web.xml
springservlet.xml
文件应该在
web-INF
文件夹中。请提取生成的war并显示结果
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   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="com.freemarker" />

    <!-- freemarker config -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="src/WEB-INF/freemarker"/>
    <property name="preferFileSystemAccess" value="false" />
</bean>

<!-- View resolvers  -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <property name="cache" value="true"/>
    <property name="prefix" value=""/>
    <property name="suffix" value=".ftl"/>
</bean>