Announcement Announcement Module
No announcement yet.
Injection into WebApplicationInitializer Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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

    public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
        Environment env;
        protected Class<?>[] getRootConfigClasses() {
            return new Class<?>[]{PersistenceJPAConfig.class};
        protected Class<?>[] getServletConfigClasses() {
            return new Class<?>[]{WebConfiguration.class};
        protected String[] getServletMappings() {
            return new String[]{"/api/*"};
        protected javax.servlet.Filter[] getServletFilters() {
            return new javax.servlet.Filter[]{new OpenEntityManagerInViewFilter()};
        public void onStartup(ServletContext servletContext) throws ServletException {
            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