首页 > 解决方案 > Spring Security 与部署在 tomcat serverINFO 中的 Jersey REST 绑定:在类路径上未检测到 Spring WebApplicationInitializer 类型

问题描述

我有一个使用 Jersey Rest & Spring Security 实现的应用程序,位于 tomcat/webapps 文件夹下。我正在使用命令提示符使用 tomcat 启动命令并收到此消息。不幸的是,服务器开始工作。

我正在使用基于注释的方法来配置 bean。

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter 
{
// My configuratio code
}

web.xml 有 spring & jersey

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         id="WebApp_ID" version="3.0">
    <display-name>TestApplication</display-name>
  
    <servlet> 
        <servlet-name>TestApplication</servlet-name> 
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.MyApplication</param-value>  
        </init-param>
        <load-on-startup>1</load-on-startup> 
        <async-supported>true</async-supported>
    </servlet>
   
    <servlet-mapping> 
        <servlet-name>TestApplication</servlet-name> 
        <url-pattern>/rest/*</url-pattern> 
    </servlet-mapping>
    
    
    <listener>
        <listener-class>com.MyContextListener</listener-class>    
    </listener>
    
      <!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext
       instead of the default XmlWebApplicationContext -->
      <context-param>
          <param-name>contextClass</param-name>
          <param-value>
              org.springframework.web.context.support.AnnotationConfigWebApplicationContext
          </param-value>
      </context-param>
    
      <!-- Configuration locations must consist of one or more comma- or space-delimited
           fully-qualified @Configuration classes. Fully-qualified packages may also be
           specified for component-scanning -->
      <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>com.infor.seService.ui.sso.WebSecurityConfig</param-value>
      </context-param>
    
      <!-- Bootstrap the root application context as usual using ContextLoaderListener -->
      <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
</web-app>

我没有使用任何弹簧靴 我不确定是否需要修复此错误,因为我使用的是基于注释的方法。任何参考文章都非常适用。

标签: springrestspring-securityjerseytomcat9

解决方案


推荐阅读