Spring Boot启动报错: Could not resolve placeholder 'spring.servlet.multipart.location' 解决方法

你在启动Spring Boot项目时遇到了以下错误:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.servlet.multipart.location' in value "${spring.servlet.multipart.location}"

这个错误通常是因为你在配置文件中引用了'spring.servlet.multipart.location'属性,但没有在配置文件中配置对应的值。如果你不想使用这个属性,可以将引用它的地方删除即可。

解决方法

如果你确定不需要这个属性,可以按照以下两种方式解决报错:

  1. 删除引用: 在你的配置文件中找到引用了'spring.servlet.multipart.location'的地方,将它删除。比如,在application.properties文件中删除类似这样的配置行:
spring.servlet.multipart.location=${spring.servlet.multipart.location}
  1. 忽略未解析的属性: 如果你的配置文件中有其他的属性需要使用,但是不需要'spring.servlet.multipart.location'这个属性,你可以在启动类上添加注解'@SpringBootApplication'的'exclude'属性,将'MultipartAutoConfiguration'排除掉。例如:
@SpringBootApplication(exclude = {MultipartAutoConfiguration.class})
public class YourApplication {
    public static void main(String[] args) {
        SpringApplication.run(YourApplication.class, args);
    }
}

排除掉'MultipartAutoConfiguration'后,Spring Boot将不会加载处理文件上传的相关配置,包括'spring.servlet.multipart.location'。

无论使用哪种方式,都需要确保你的配置文件正确且不包含无法解析的属性,这样才能避免报错。

Spring Boot启动报错: Could not resolve placeholder 'spring.servlet.multipart.location' 解决方法

原文地址: http://www.cveoy.top/t/topic/F41 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录