当前位置: 首页 > 知识库问答 >
问题:

无法启动嵌入式容器;嵌套异常java.lang.IllegalArgumentException:在servlet映射中无效

齐运诚
2023-03-14

我正在用jersey开发spring boot中的应用程序。我是Spring靴的新手。当我尝试在tomcat7.0中部署war时,我得到了以下错误

org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/leasing-management-spring]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1768)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

org.apache.catalina.core.StandardContext.startInternal:无法启动嵌入式容器;嵌套异常StandardContext.java:5156:无效的*/在servlet映射在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)在java.lang.IllegalArgumentException(org.apache.catalina.core.StandardContext.addServletMapping)在StandardContext.java:3075(org.apache.catalina.core.StandardContext.addServletMapping)在StandardContext.java:3050(org.apache.catalina.core.ApplicationServletRegistration.addMapping)在ApplicationServletRegistration.java:192(org.springframework.boot.context.embedded.ServletRegistrationBean.configure)在ServletRegistrationBean.java:211(SpringBootServletInitializer.java:133)在org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:124)在org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringServletContainerInitializer.java:175)在org.springframework.context.ApplicationContextException(java.lang.IllegalArgumentException)在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)…10更多由:org.springframework.context.support.AbstractApplicationContext.refresh:无效的*/在servlet映射在AbstractApplicationContext.java:474(org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh)在EmbeddedWebApplicationContext.java:118(org.springframework.boot.SpringApplication.refresh)在SpringApplication.java:687(org.springframework.boot.SpringApplication.run)在SpringApplication.java:321(org.springframework.boot.context.web.SpringBootServletInitializer.run)在org. springframe. boot. conttext. EmbeddedWebApplication ationContext. java: 195)在org. springframe. boot. text. embeddedWebApplication ationContext. java: 222)在org. springframe. boot. text. embeddedWebApplication. access 0美元(EmbeddedWebApplication ationContext. java:

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0"

<filter>
    <filter-name>metricFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>metricFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextAttribute</param-name>
        <param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

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

砰.xml

http://maven.apache.org/maven-v4_0_0.xsd"

<properties>
    <project.java.version>1.8</project.java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jetty.version>9.3.0.v20150612</jetty.version>
    <jersey.version>1.19</jersey.version>
    <spring-boot.version>1.2.6.RELEASE</spring-boot.version>
    <slf4j.version>1.6.6</slf4j.version>
    <logback.version>1.0.9</logback.version>
    <hibernate.version>4.3.6.Final</hibernate.version>
    <spring.version>3.2.3.RELEASE</spring.version>
    <atomikos.version>3.8.0</atomikos.version>
    <sql.driver.version>4.0</sql.driver.version>
</properties>
<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-guice</artifactId>
        <version>${jersey.version}</version>
    </dependency>


    <!-- <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> 
        <version>${jersey.version}</version> </dependency> -->

    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>2.6.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-xml-provider</artifactId>
        <version>2.6.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
        <version>${spring-boot.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>${spring-boot.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>${spring-boot.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- Spring boot Tomcat Dependency -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <version>${spring-boot.version}</version>
        <scope>provided</scope>
    </dependency>
  <repositories>
    <repository>
        <id>java.net</id>
        <url>http://download.java.net/maven/2/</url>
    </repository>
</repositories>

<build>
    <finalName>leasing-management-spring</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>${project.java.version}</source>
                <target>${project.java.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty.version}</version>

            <configuration>
                <reload>automatic</reload>
                <scanIntervalSeconds>20</scanIntervalSeconds>
                <stopKey>todostop</stopKey>
                <stopPort>9999</stopPort>
            </configuration>

          </plugin>
       </plugins>
    </build>

</project>

Spring启动代码

@SpringBootApplication 
    public class Application extends SpringBootServletInitializer {

  @Override
    protected SpringApplicationBuilder configure
     (SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

public static void main(String[] args) throws Exception{
    SpringApplication.run(Application.class, args);

}

@Bean
public ServletRegistrationBean jerseyServlet(){
    ServletRegistrationBean register = 
    new ServletRegistrationBean(new ServletContainer(),"*/");
    register.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerseyInitialization.class.getName());
    return register;
}}

Jersey配置公共类Jersey初始化扩展了ResourceConfig{

}


共有1个答案

宇文飞翮
2023-03-14

异常(或者更确切地说是它的原因)准确地告诉你哪里出了问题:

servlet映射中的*/无效

在 Java 代码中,您尝试实例Servlet 注册Bean,如下所示:

ServletRegistrationBean register = 
new ServletRegistrationBean(new ServletContainer(),"*/");

因为异常情况表明 */ 不是有效的 servlet 映射。您可能想要 /* 来代替。

根据Java Servlet规范:

在Web应用程序部署描述符中,以下语法用于定义映射:

  • 以“/”字符开头并以“/*”后缀结尾的字符串用于路径映射
  • 以“*”开头的字符串前缀用作扩展映射
  • 空字符串(“”)是一种特殊的URL模式,它精确地映射到应用程序的上下文根,即表单的请求http://host:port//.在本例中,路径信息为“/”,servlet路径和上下文路径为空字符串(“”)。
  • 仅包含“/”字符的字符串表示应用程序的“默认”servlet。在这种情况下,servlet路径是请求URI减去上下文路径,路径信息为空
  • 所有其他字符串仅用于精确匹配
 类似资料: