Results 1 to 3 of 3

Thread: Problem injecting dependencies into @Configuration class

  1. #1
    Join Date
    Sep 2007
    Location
    London,UK
    Posts
    21

    Default Problem injecting dependencies into @Configuration class

    Hi Guys

    I'm trying to create a custom exception resolver chain as follows:

    Code:
    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages = "web.client")
    public class WebApplicationConfiguration extends WebMvcConfigurerAdapter {
    
    	private static final Logger log = LoggerFactory.getLogger(WebApplicationConfiguration.class);
    
    	@Inject
    	private MonitoringExceptionResolver resolver;
    
    	@Override
    	public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
    		log.debug("configuring exception resolvers");
    		super.configureHandlerExceptionResolvers(exceptionResolvers);
    		exceptionResolvers.add(new DefaultHandlerExceptionResolver());
    		exceptionResolvers.add(new AnnotationMethodHandlerExceptionResolver());
    		exceptionResolvers.add(new ResponseStatusExceptionResolver());
    		exceptionResolvers.add(resolver);
    	}
    
    }
    However, I get NPE later in the execution chain because the "resolver" class field above is always null. This class should be successfully wired elsewhere using component scanning. Why is it always null in the above? Am I doing something wrong?

    Regards...
    Last edited by rgladwell; Oct 16th, 2012 at 09:54 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    For starters your base package isn't a valid package (starts with a .). Also @Inject might be too late so instead try @Autowired.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2007
    Location
    London,UK
    Posts
    21

    Default

    Please ignore the base package, I redacted the rest of it so-as not to display personal information (now fixed above)

    As for @Autowired, I already tried that and that didn't work either.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •