Announcement Announcement Module
Collapse
No announcement yet.
Injection into WebApplicationInitializer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injection into WebApplicationInitializer

    Good day. I'm a newbie in Java and Spring, so may be the question is dumb. So. I have an app initializer, based on AbstractAnnotationConfigDispatcherServletInitializ er. (The code is mostly from https://github.com/olivergierke/spring-restbucks)

    Code:
    @PropertySource("classpath:/environment.properties")
    public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    
        @Autowired
        Environment env;
    
        @Override
        protected Class<?>[] getRootConfigClasses() {
            return new Class<?>[]{PersistenceJPAConfig.class};
        }
    
        @Override
        protected Class<?>[] getServletConfigClasses() {
            return new Class<?>[]{WebConfiguration.class};
        }
    
        @Override
        protected String[] getServletMappings() {
            return new String[]{"/api/*"};
        }
    
        @Override
        protected javax.servlet.Filter[] getServletFilters() {
            return new javax.servlet.Filter[]{new OpenEntityManagerInViewFilter()};
        }
    
        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            super.onStartup(servletContext);
    
            log.debug(String.valueOf(env));
    
            servletContext.addListener(new ContextListener());
        }
    }
    And I want to use some beans, injecting them into this class. For a purance I took a code for accessing properties from manual. But injected property env is null. And any other beans injected as nulls. What I'm doing wrong?

    Injection (and autowiring) works well in other classes. The only idea that comes to my mind - is that DI starts working AFTER initialization of servlet. Isn't it?

    Thank you.

  • #2
    Nobody knows?
    It's a pity

    Comment

    Working...
    X