• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object Mapper configuration broken when adding PropertySourcesPlaceholderConfigurer

 
Bartender
Posts: 667
14
TypeScript Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to get a value from a property file using @Value("${propertyName}")
Before it wasn't able to get the value, so I added a PropertySourcesPlaceholderConfigurer to my ServletConfiguration.  Doing this is throwing an exception that the ObjectMapper is null.  If I just delete the PropertySourcesPlaceholderConfigurer bean configuration then it doesn't throw the exception anymore.  The objectMapper is configured in the RootContextConfiguration.

The exception is being thrown when the ObjectMapper is being set down there at the bottom of configureMessageConverters.


I had never had any problem with the objectmapper until adding that propertysourceconfig bean in there.
Any guidance would be greatly appreciated!!!
thanks!!
 
Al Hobbs
Bartender
Posts: 667
14
TypeScript Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay so I figured out the problem after looking at the log.  I needed to have the bean config method static.
In the log this message popped up:
17:20:43.273 [http-nio-8080-exec-3] WARN  org.springframework.context.annotation.ConfigurationClassEnhancer - @Bean method ServletContextConfiguration.propertySourcesPlaceholderConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean Javadoc for complete details

Thanks if you read it.
Anyone who finds this in the future I guess make sure to make the config method static in this case!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic