【问题标题】:web.xml configuration as annotationsweb.xml 配置作为注解
【发布时间】:2013-11-17 16:16:33
【问题描述】:

我正在尝试启动一个使用 Vaadin 和 Spring 的基本示例项目。我怎样才能把这样的xml配置:

 <context-param>
      <param-name>contextClass</param-name>
      <param-value>
        org.springframework.web.context.support.AnnotationConfigWebApplicationContext
      </param-value>
    </context-param>

   <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.app.config.AppConfig</param-value>
   </context-param>

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

到这样的基于 java 的配置:

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class,       widgetset = "com.rrd.mavenproject1.AppWidgetSet")
public static class Servlet extends VaadinServlet {
}

【问题讨论】:

    标签: java xml servlets configuration annotations


    【解决方案1】:

    你不能。如果您有自定义 Servlet XxxListener,则可以使用 @WebListener 对其进行注释。在这种情况下,您尝试加载您无法控制的ContextLoaderListener

    上下文参数对应用程序来说是全局的,因此不能添加到单个@WebServlet 注释中。

    您可能正在寻找的是 Servlet API 的 ServletContainerInitializer 或 Spring 的 WebApplicationInitializer 来执行 Java 配置。

    在其中任何一个中,您都可以访问ServletContext,您可以在其中add context parameterslisteners。这些类的优势在于您可以从 Spring 上下文中创建 Servlet、过滤器和侦听器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-16
      • 2015-05-29
      • 2012-11-13
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      相关资源
      最近更新 更多