bug(Tomcat):java.lang.IllegalArgumentException: servlet映射中的<url pattern>[opus/addPage]无效

文章讲述了在web开发中遇到的两种启动失败的错误情况。一种是由于@WebServlet注解中缺少反斜杠引起的URL映射无效,另一种是两个Servlet映射到了同一个URL模式导致的冲突。解决方案分别是对注解添加反斜杠和修改Servlet的URL映射以避免冲突。

引出

web开发常见bug,项目启动失败


报错信息:

java.lang.IllegalArgumentException: servlet映射中的<url pattern>[opus/addPage]无效

在这里插入图片描述

问题描述:

启动tomcat就报错,项目启动不起来,报错信息是url pattern无效。这个问题是因为@WebServlet(value = “/us”) 中反斜杠 / 没有写;

在这里插入图片描述

在这里插入图片描述

相同类型【启动失败】的报错问题如下:
java.lang.IllegalArgumentException: 名为 [com.tianju.servlet.opus.AddPagServlet]和 [com.tianju.servlet.opus.AddServlet] 的servlet不能映射为一个url模式(url-pattern) [/opus/addPage]

这个问题是因为两个Serlet 指向了同一个路径

在这里插入图片描述在这里插入图片描述

解决方案:

(1)@WebServlet(value = “/us”) 中反斜杠 / 没有写;把反斜杠加上

(2)两个Serlet 指向同一个路径;把其中一个@WebServlet() 的路径换成别的


总结

🐛 bug不可怕,找到它并消灭就好了!

(1)@WebServlet(value = “/us”) 中反斜杠 / 没有写;把反斜杠加上

(2)两个Serlet 指向同一个路径;把其中一个@WebServlet() 的路径换成别的

<?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>com.carbonfootprint</groupId> <artifactId>carbonfootprint-common</artifactId> <version>3.6.5</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>carbonfootprint-common-chainmaker</artifactId> <description> carbonfootprint-common-maker存证合约 </description> <dependencyManagement> <dependencies> <!-- 锁定gRPC全家桶版本 --> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-bom</artifactId> <version>1.50.0</version> <type>pom</type> <scope>import</scope> </dependency> <!-- 锁定Netty版本 --> <dependency> <groupId>io.netty</groupId> <artifactId>netty-bom</artifactId> <version>4.1.77.Final</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.carbonfootprint</groupId> <artifactId>carbonfootprint-common-core</artifactId> </dependency> <dependency> <groupId>org.chainmaker</groupId> <artifactId>chainmaker-sdk-java</artifactId> <version>2.3.2</version> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-tcnative-openssl-static</artifactId> <scope>system</scope> <version>2.0.39.Final</version> <systemPath>${project.basedir}/lib/netty-tcnative-openssl-static-2.0.39.Final.jar</systemPath> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-tcnative-boringssl-static</artifactId> <version>2.0.56.Final</version> <classifier>linux-x86_64</classifier> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-tcnative-boringssl-static</artifactId> <version>2.0.56.Final</version> <classifier>osx-aarch_64</classifier> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-handler</artifactId> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-api</artifactId> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty</artifactId> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> </dependency> </dependencies> </project> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.carbonfootprint</groupId> <artifactId>carbonfootprint-modules</artifactId> <version>3.6.5</version> </parent> <groupId>com.carbonfootprint.portalmgmt</groupId> <artifactId>carbonfootprint-portalmgmt</artifactId> <packaging>jar</packaging> <version>1.0.0</version> <name>carbonfootprint-portalmgmt</name> <url>http://maven.apache.org</url> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- SpringCloud Alibaba Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- SpringCloud Alibaba Nacos Config --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency> <!-- SpringCloud Alibaba Sentinel --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- SpringBoot Actuator --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>com.carbonfootprint</groupId> <artifactId>carbonfootprint-common-log</artifactId> </dependency> <dependency> <groupId>com.carbonfootprint.boot</groupId> <artifactId>carbonfootprint-file-spring-boot-starter</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.carbonfootprint</groupId> <artifactId>carbonfootprint-common-swagger</artifactId> </dependency> <!-- Lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>com.carbonfootprint</groupId> <artifactId>carbonfootprint-api-system</artifactId> </dependency> <dependency> <groupId>com.carbonfootprint</groupId> <artifactId>carbonfootprint-common-security</artifactId> <exclusions> <exclusion> <artifactId>poi-ooxml</artifactId> <groupId>org.apache.poi</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>net.sf.dozer</groupId> <artifactId>dozer</artifactId> </dependency> <!-- EasyExcel --> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>4.0.3</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> </dependency> <!-- 区块链 --> <dependency> <groupId>com.carbonfootprint</groupId> <artifactId>carbonfootprint-common-chainmaker</artifactId> <version>3.6.5</version> </dependency> </dependencies> <build> <finalName>${project.artifactId}-${project.version}.${build.time}</finalName> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.5.0</version> <executions> <execution> <id>timestamp-property</id> <goals> <goal>timestamp-property</goal> </goals> <configuration> <name>build.time</name> <pattern>yyyyMMddHHmmssSSS</pattern> <locale>zh_CN</locale> <timeZone>GMT+8</timeZone> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> 报错 Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) Caused by: java.lang.UnsatisfiedLinkError: failed to load the required native library at io.netty.handler.ssl.OpenSsl.ensureAvailability(OpenSsl.java:616) at io.netty.handler.ssl.SslContext.newClientContextInternal(SslContext.java:835) at io.netty.handler.ssl.SslContextBuilder.build(SslContextBuilder.java:615) at org.chainmaker.sdk.RpcServiceClient.initManagedChannel(RpcServiceClient.java:160) at org.chainmaker.sdk.RpcServiceClient.<init>(RpcServiceClient.java:83) at org.chainmaker.sdk.RpcServiceClient.newServiceClient(RpcServiceClient.java:91) at org.chainmaker.sdk.GrpcClientFactory.createRpcClient(GrpcClientFactory.java:126) at org.chainmaker.sdk.GrpcClientFactory.create(GrpcClientFactory.java:109) at org.chainmaker.sdk.GrpcClientFactory.create(GrpcClientFactory.java:21) at org.apache.commons.pool2.BasePooledObjectFactory.makeObject(BasePooledObjectFactory.java:70) at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:571) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:298) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:223) at org.chainmaker.sdk.ChainClient.sendTxRequest(ChainClient.java:2778) at org.chainmaker.sdk.ChainClient.sendRequest(ChainClient.java:3201) at org.chainmaker.sdk.ChainClient.proposalRequest(ChainClient.java:3107) at org.chainmaker.sdk.ChainClient.getChainConfig(ChainClient.java:1103) at com.carbonfootprint.common.maker.configure.ChainConfig.getChainConfig(ChainConfig.java:11) at com.carbonfootprint.portalmgmt.CarbonFootprintPortalMgmtApplication.main(CarbonFootprintPortalMgmtApplication.java:32) ... 8 more Caused by: java.lang.IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_linux_x86_64, netty_tcnative_linux_x86_64_fedora, netty_tcnative_x86_64, netty_tcnative] at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:114) at io.netty.handler.ssl.OpenSsl.loadTcNative(OpenSsl.java:725) at io.netty.handler.ssl.OpenSsl.<clinit>(OpenSsl.java:151) at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:169) at org.chainmaker.sdk.RpcServiceClient.getSslContextBuilder(RpcServiceClient.java:204) at org.chainmaker.sdk.RpcServiceClient.initManagedChannel(RpcServiceClient.java:147) ... 23 more Suppressed: java.lang.IllegalStateException: Multiple resources found for 'META-INF/native/libnetty_tcnative_linux_x86_64.so' with different content: [jar:file:/app/run.jar!/BOOT-INF/lib/netty-tcnative-openssl-static-2.0.39.Final.jar!/META-INF/native/libnetty_tcnative_linux_x86_64.so, jar:file:/app/run.jar!/BOOT-INF/lib/netty-tcnative-boringssl-static-2.0.61.Final-linux-x86_64.jar!/META-INF/native/libnetty_tcnative_linux_x86_64.so] at io.netty.util.internal.NativeLibraryLoader.getResource(NativeLibraryLoader.java:301) at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:173) at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:105) ... 28 more Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative_linux_x86_64_fedora at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239) at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:105) ... 28 more Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_tcnative_linux_x86_64_fedora.so at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:186) ... 29 more Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_linux_x86_64_fedora in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1124) at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38) at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:396) at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161) ... 29 more Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_linux_x86_64_fedora in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1124) at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:430) at java.security.AccessController.doPrivileged(Native Method) at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:422) at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:388) ... 30 more Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative_x86_64 at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239) at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:105) ... 28 more Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_tcnative_x86_64.so at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:186) ... 29 more Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_x86_64 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1124) at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38) at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:396) at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161) ... 29 more Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative_x86_64 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1124) at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:430) at java.security.AccessController.doPrivileged(Native Method) at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:422) at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:388) ... 30 more Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_tcnative at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239) at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:105) ... 28 more Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_tcnative.so at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:186) ... 29 more Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1124) at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38) at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:396) at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161) ... 29 more Suppressed: java.lang.UnsatisfiedLinkError: no netty_tcnative in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1124) at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:430) at java.security.AccessController.doPrivileged(Native Method) at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:422) at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:388) ... 30 more
最新发布
12-10
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arya's Blog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值