【问题标题】:Jetty 7 web.xml configuration for Spring web 3.0.5Spring web 3.0.5 的 Jetty 7 web.xml 配置
【发布时间】:2011-10-27 01:45:12
【问题描述】:

我在 eclipse indigo 中配置了一个 Jetty 7 嵌入式模式。当我在 Eclipse 中启动码头时,它似乎没有加载我的 web.xml 和 spring-servlet.xml 配置。我在网上搜索,似乎每个人都在做与我相同的配置,但我的没有加载。我忘了什么吗?还是 Jetty 7 配置与 jetty 6 不同?

Main.java

  Server server = new Server(8080);

  WebAppContext context = new WebAppContext();
  context.setResourceBase("../jettyserver/webapp");
  context.setContextPath("/");
  context.setParentLoaderPriority(true);

  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[]{ context, new DefaultHandler()});

  server.setHandler(context);
  try {
         server.start();
     server.join();
  } catch (Exception e) {
     e.printStackTrace();
  }

web.xml

 <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>

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

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

<servlet>
    <servlet-name>spring</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-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

 <context:annotation-config />
     <context:component-scan base-package="com.jetty.controller" />

     <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>

【问题讨论】:

    标签: spring spring-mvc jetty web.xml


    【解决方案1】:

    这里不是专家,但如果您使用的是 eclipse,我会说您的资源库可能有问题。

    根据您在此处使用 Eclipse 的方式(WTP、Maven 等),编译后的代码最终会出现在某个目标文件夹中。但是,您的 JSP 和所有可能不会遵循或可能不在您认为的位置。

    编译您的代码并查看您的目标文件夹,看看它在哪里。我做了类似的事情,但它正在测试代码,所以我真的不在乎路径是否链接到我的 IDE。除了这些之外,我们的版本几乎相同,应用差异除外:

        WebAppContext webapp = new WebAppContext();
        webapp.setDescriptor("target/app/WEB-INF/web.xml");
        webapp.setResourceBase("target/app");
        webapp.setContextPath("/app");
    

    正如您在此处看到的,Eclipse 中应用程序运行时的根路径是您的工作区中项目的根路径。我设置了我的,所以它发现它是相对于项目根路径的东西,因此是那里的目标。

    但是,如果您正在寻找可以在您的环境中运行并且部署后的代码,您可能会更改特定应用程序的运行配置中的根文件夹并将其设置为直接目标(或任何适合您的方式)。

    对不起,在这里没有更果断,

    无论如何,希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-21
      • 2011-12-16
      • 2017-01-27
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 2012-11-13
      • 1970-01-01
      相关资源
      最近更新 更多