I'm working on a new Spring web app and I'm following a pattern that has worked well for earlier web apps. I have a web application configuration class:
@Configuration
@EnableWebMvc
@EnableJpaRepositories
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.example" })
@PropertySource(value = "classpath:application.properties")
public class WebApplicationConfiguration extends WebMvcConfigurerAdapter { ... }
When I start the web app (under Tomcat), I get the following error:
[RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
[RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class
[org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.BeanDefinitionStoreException:
Failed to parse configuration class [com.example.WebApplicationConfiguration];
nested exception is java.lang.IllegalArgumentException:
Attribute 'encoding' not found in attributes for annotation [org.springframework.context.annotation.PropertySource]
at org.springframework.context.annotation.ConfigurationClassParser.parse (ConfigurationClassParser.java:187)
...
Caused by: java.lang.IllegalArgumentException:
Attribute 'encoding' not found in attributes for annotation
[org.springframework.context.annotation.PropertySource]
I haven't needed to specify the encoding
attribute on the @PropertySource
annotation in earlier web apps, so I'm not sure why error is showing up now. Anyway, I tried the following:
@PropertySource(value = "classpath:application.properties", encoding = "UTF-8")
... and this made no difference, ie. I got the same error. This suggests to me that the underlying cause might not be the @PropertySource
annotation. Any suggestions on what I might be doing wrong
Errors like this are generally a sign of mixing jars from different versions of Spring. In this case the annotation processor for the @PropertySource
annotation expects the encoding
property to be there.
However at runtime it isn't there and hence it produces the error.
You want to check your (transitive) dependencies for conflicting versions (or versions you haven't managed explicitly).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.