View Javadoc

1   package org.springframework.osgi.atlassian;
2   
3   import org.springframework.beans.factory.support.DefaultListableBeanFactory;
4   import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
5   import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
6   
7   /**
8    * Application context that initializes the bean definition reader to not validate via XML Schema.  Note that by
9    * turning this off, certain defaults won't be populated like expected.  For example, XML Schema provides the default
10   * autowire value of "default", but without this validation, that value is not set so autowiring will be turned off.
11   *
12   * This class exists in the same package as the parent so the log messages won't get confused as the parent class
13   * logs against the instance class.
14   *
15   * @since 2.5.0
16   */
17  public class NonValidatingOsgiBundleXmlApplicationContext extends OsgiBundleXmlApplicationContext
18  {
19      public NonValidatingOsgiBundleXmlApplicationContext(String[] configLocations)
20      {
21          super(configLocations);
22      }
23  
24      @Override
25      protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader)
26      {
27          super.initBeanDefinitionReader(beanDefinitionReader);
28          beanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
29          beanDefinitionReader.setNamespaceAware(true);
30      }
31  
32      @Override
33      protected void customizeBeanFactory(final DefaultListableBeanFactory beanFactory)
34      {
35          if (Boolean.getBoolean("atlassian.disable.spring.cache.bean.metadata"))
36          {
37              beanFactory.setCacheBeanMetadata(false);
38          }
39          super.customizeBeanFactory(beanFactory);
40      }
41  
42      @Override
43      protected DefaultListableBeanFactory createBeanFactory()
44      {
45          if (Boolean.getBoolean("atlassian.disable.spring.jaas"))
46          {
47              return new UnsecureListableBeanFactory(getInternalParentBeanFactory());
48          }
49          return super.createBeanFactory();
50      }
51  }