Attributes should be specified via @SpringBootApplication问题解决
Posted 沉默着忍受
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Attributes should be specified via @SpringBootApplication问题解决相关的知识,希望对你有一定的参考价值。
项目场景: 在spring boot启动方法上设置@EnableAutoConfiguration注解,如下所示:
问题描述:
@EnableAutoConfiguration(exclude = MultipartAutoConfiguration.class)
@SpringBootApplication
public class CloudApplication extends ServletInitializer
public static void main(String[] args)
SpringApplication.run(CloudApplication.class, args);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
return application.sources(CloudApplication.class);
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver()
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
resolver.setResolveLazily(true);//resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
resolver.setMaxInMemorySize(40960);
resolver.setMaxUploadSize(5 * 1024 * 1024);//上传文件大小 5M 5*1024*1024
return resolver;
这里会发生Attributes should be specified via @SpringBootApplication错误
原因分析:
经过排查代码发现,@SpringBootApplication注解中已经包含@EnableAutoConfiguration注解,不需要重复定义@EnableAutoConfiguration注解。解决方案:
去掉@EnableAutoConfiguration注解,将(exclude = MultipartAutoConfiguration.class)赋予@SpringBootApplication,改进后:@SpringBootApplication(exclude = MultipartAutoConfiguration.class)
public class CloudApplication extends ServletInitializer
public static void main(String[] args)
SpringApplication.run(CloudApplication.class, args);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
return application.sources(CloudApplication.class);
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver()
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
resolver.setResolveLazily(true);//resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
resolver.setMaxInMemorySize(40960);
resolver.setMaxUploadSize(5 * 1024 * 1024);//上传文件大小 5M 5*1024*1024
return resolver;
以上是关于Attributes should be specified via @SpringBootApplication问题解决的主要内容,如果未能解决你的问题,请参考以下文章
Attributes should be specified via @SpringBootApplication问题解决
Vue3---error xx should be on a new line
FluentAssertions:ShouldBeEquivalentTo vs Should().Be() vs Should().BeEquivalentTo()?
[1.1]Knowledge that should be prepared