简体   繁体   English

Spring Web 3.0.5的Jetty 7 web.xml配置

[英]Jetty 7 web.xml configuration for Spring web 3.0.5

I configured a Jetty 7 embedded mode in eclipse indigo. 我在eclipse indigo中配置了Jetty 7嵌入式模式。 When i start jetty in eclipse it seems not loading my web.xml and spring-servlet.xml configuration. 当我在Eclipse中启动码头时,似乎没有加载我的web.xml和spring-servlet.xml配置。 I search on the net, it seems everybody doing the same configuration as me but mine doesn't load. 我在网上搜索,似乎每个人都和我做相同的配置,但是我的没有加载。 Did i forgot something ? 我忘了什么吗? or Jetty 7 configuration its different than jetty 6 ? 还是Jetty 7的配置与码头6不同?

Main.java 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 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 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>

Not an expert here but if you are using eclipse I'd say there could be a problem with your resource base. 这里不是专家,但是如果您使用Eclipse,我会说您的资源库可能存在问题。

Depending on how you use Eclipse here (WTP, Maven etc) the compiled code will end up in the target folder somewhere. 根据您在此处使用Eclipse(WTP,Maven等)的方式,编译后的代码将最终存储在目标文件夹中的某个位置。 However your JSP and all may not follow or may not be where you'd think they are. 但是,您的JSP以及所有JSP可能不会遵循或可能不在您认为的位置。

Compile your code and look in your target folder see where it is. 编译代码,然后在目标文件夹中查看其位置。 I do something similar but it's testing code so I don't really care if the paths are linked to my IDE. 我做了类似的事情,但是它正在测试代码,所以我真的不在乎路径是否链接到我的IDE。 our versions are pretty much identical, applicative differences aside, except for these : 除了以下内容外,我们的版本几乎完全相同,但适用性不同:

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

As you can see here the root path of the application run-time within Eclipse is your project's root path in your workspace. 如您所见,Eclipse中应用程序运行时的根路径是工作空间中项目的根路径。 I set mine so it finds it's stuff relative to the project's root path, hence the target in there. 我设置了我的,以便它找到相对于项目根路径的东西,因此是其中的目标。

If however you are looking for code that runs in both your environment and once deployed you could probably change the root folder in the run configuration for your particular application and set it to target directly (or whatever works for you). 但是,如果您要查找在环境中都可以运行且已部署的代码,则可以更改特定应用程序的运行配置中的根文件夹,并将其设置为直接目标(或任何适用于您的目标)。

Sorry for not being more decisive here, 抱歉,在这里没有决定性的内容,

Anyways, hope this helps. 无论如何,希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM