WebMvcConfigurerAdapter过时替代方法及server.context-path不生效解决方法。

本文解决SpringBoot框架中WebMvcConfigurerAdapter过时的问题,介绍如何使用WebMvcConfigurer替代,并调整项目路径配置,确保应用正确运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题一:使用SpringBoot框架中的WebMvcConfigurerAdapter中的配置时,发现编译器提示已失效过时,如下图所示:

解决方法:使用下面WebMvcConfigurer替代

@Configuration
public class MyMvcConfig implements WebMvcConfigurer{
    //代码段
}

问题二:在application.properties中设置项目路径采用的是server.context-path=/hjbzf,如下图:

发现运行时,路径并没有变化成/hjbzf,依旧是/,但是端口号已改为7777,在网上查询资料后,发现springboot将项目路径改为了server.servlet.context-path,所以应改为:

server.servlet.context-path=/hjbzf
server.port=7777

重新运行即可

Abnormal build process termination: "D:\javagj\idea\IntelliJ IDEA 2022.3.1\jbr\bin\java.exe" -Xmx700m -Djava.awt.headless=true "-Djna.boot.library.path=D:\javagj\idea\IntelliJ IDEA 2022.3.1/lib/jna/amd64" -Djna.nosys=true -Djna.noclasspath=true --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dpreload.project.path=E:/java_workspace/Zhgd4.0-Cloud -Dpreload.config.path=C:/Users/Administrator/AppData/Roaming/JetBrains/IntelliJIdea2022.3/options -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Didea.IntToIntBtree.page.size=32768 -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=7903707484277119235 -Dfile.encoding=GBK -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2022.3 "-Didea.home.path=D:/javagj/idea/IntelliJ IDEA 2022.3.1" -Didea.config.path=C:/Users/Administrator/AppData/Roaming/JetBrains/IntelliJIdea2022.3 -Didea.plugins.path=C:/Users/Administrator/AppData/Roaming/JetBrains/IntelliJIdea2022.3/plugins -Djps.log.dir=C:/Users/Administrator/AppData/Local/JetBrains/IntelliJIdea2022.3/log/build-log "-Djps.fallback.jdk.home=D:/javagj/idea/IntelliJ IDEA 2022.3.1/jbr" -Djps.fallback.jdk.version=17.0.5 -Dio.netty.noUnsafe=true -Djava.io.tmpdir=C:/Users/Administrator/AppData/Local/JetBrains/IntelliJIdea2022.3/compile-server/zhgd-cloud_26beeabf/_temp_ -Djps.backward.ref.index.builder=true -Dtmh.instrument.annotations=true -Dtmh.generate.line.numbers=true "-Djps.kotlin.home=D:\javagj\idea\IntelliJ IDEA 2022.3.1\plugins\Kotlin\kotlinc" -Dkotlin.incremental.compilation=true -Dkotlin.incremental.compilation.js=true -Dkotlin.daemon.enabled -Dkotlin.daemon.client.alive.path=\"C:\Users\ADMINI~1\AppData\Local\Temp\kotlin-idea-3171289915408307769-is-running\" -Dide.propagate.context=false -classpath "D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/java/lib/jps-launcher.jar" org.jetbrains.jps.cmdline.Launcher "D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/java/lib/jps-builders.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/java/lib/jps-builders-6.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/java/lib/jps-javac-extension.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/util.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/util_rt.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/annotations.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/3rd-party-rt.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/protobuf.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/jps-model.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/java/lib/javac2.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/forms_rt.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/java/lib/aether-dependency-resolver.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/idea_rt.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/JavaEE/lib/jasper-v2-rt.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/Kotlin/lib/jps/kotlin-jps-plugin.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/lib/util.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/eclipse/lib/eclipse-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/eclipse/lib/eclipse-common.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/ant/lib/ant-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/JavaEE/lib/javaee-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/uiDesigner/lib/jps/java-guiForms-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/space/lib/space-java-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/devkit/lib/devkit-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/platform-langInjection/lib/java-langInjection-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/javaFX/lib/javaFX-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/javaFX/lib/javaFX-common.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/Groovy/lib/groovy-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/Groovy/lib/groovy-constants-rt.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/maven/lib/maven-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/gradle-java/lib/gradle-jps.jar;D:/javagj/idea/IntelliJ IDEA 2022.3.1/plugins/JPA/lib/jps/javaee-jpa-jps.jar" org.jetbrains.jps.cmdline.BuildMain 127.0.0.1 50210 1602d901-bd98-43c6-8a4a-967c2a85f0cd C:/Users/Administrator/AppData/Local/JetBrains/IntelliJIdea2022.3/compile-server # OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000d4400000, 536870912, 0) failed; error='页面文件太小,无法完成操作。' (DOS error/errno=1455) # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 536870912 bytes for G1 virtual space # An error report file with more information is saved as: # C:\Users\Administrator\AppData\Local\JetBrains\IntelliJIdea2022.3\compile-server\hs_err_pid42716.log
07-04
2025-03-15 09:57:03.676[ERROR][main]-Application run failed java.lang.RuntimeException: Server runtime path not found at io.iec.edp.caf.commons.runtime.CafEnvironment.getServerRTPath(CafEnvironment.java:277) at io.iec.edp.caf.common.environment.EnvironmentUtil.getServerRTPath(EnvironmentUtil.java:65) at com.inspur.edp.patch.runtime.agent.EnvironmentPropertiesListener.onApplicationEvent(EnvironmentPropertiesListener.java:35) at com.inspur.edp.patch.runtime.agent.EnvironmentPropertiesListener.onApplicationEvent(EnvironmentPropertiesListener.java:23) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:178) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:171) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:145) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82) at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63) at java.util.ArrayList.forEach(ArrayList.java:1257) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:375) at org.springframework.boot.SpringApplication.run(Sprin
03-16
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/maven/jyrepo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/maven/jyrepo/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder] 2025-03-27 08:39:36.894 INFO 17776 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$e133a5ad] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2025-03-27 08:39:37.404 ERROR 17776 --- [ main] o.s.boot.SpringApplication : Application run failed java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application-dev.yml' at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:524) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:462) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:443) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:425) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
03-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值