Note that there are some explanatory texts on larger screens.

plurals
  1. POAutowiring issue with bean in spring
    primarykey
    data
    text
    <p>I am new to Spring and having an issue and kind of stuck for 2 days. I wanted to post the question and see if i get any answers. I am implementing rest based service.In my stuff we have three different modules 1)service module (where we have the service implementation and also the url are defined) 2)business module(this is the module where we do some business logic after getting data from data base) 3)Data module(which just gets and puts the stuff from data base)</p> <p>each module has its own application context file .And i have a generic configuration file which loads all the context files and also any properties file specific to the enviornment in my tests in each module also i load the generic context file which loads my context file the generic context file looks like the following</p> <p></p> <p>apart from this i have some other beans which loads all the properties files which are specific to env.</p> <p>So my domain module context looks like following</p> <pre><code>&lt;bean id="DALConfigLoader" class="ConfigurationInit" init-method="initializeConnection" &gt; &lt;constructor-arg value="classpath:/environmentConfig/$env/config.json"/&gt; &lt;/bean&gt; </code></pre> <p>So basically here i am loading a configuration file which has to be loaded before to load of any thing .and it has to call the intilizeconnection method which basically created the connection poling and all..</p> <pre><code>&lt;bean id="dao" class="OfferPriceDAOImpl" depends-on="DALConfigLoader"&gt; &lt;constructor-arg index="0" ref="offerprice"&gt;&lt;/constructor-arg&gt; &lt;constructor-arg index="1" ref="myoracl"&gt;&lt;/constructor-arg&gt; &lt;constructor-arg index="2"&gt;&lt;null/&gt;&lt;/constructor-arg&gt; &lt;/bean&gt; </code></pre> <p>this is the bean where i have the crud operations to the database table and as i mentioned before before loading any of my dal it has to load the DALConfigLoader </p> <p>2)In my business module i have the following code</p> <pre><code> @Component public class ManagerImpl implements IManager { @Autowired private IOfferPriceDAO offerPriceDAO;///this is my domain code } </code></pre> <p>and my configuration file looks like the following</p> <pre><code> &lt;beans&gt; &lt;context:component-scan base-package="basepackage"/&gt; &lt;/beans&gt; </code></pre> <p>in my business module tests i load the files like this</p> <pre><code> @ContextConfiguration(locations = { "classpath:GenericContext.xml" }) public class ManagerImplTest extends AbstractTestNGSpringContextTests { @Autowired ItemPricingManager mgr; } </code></pre> <p>So here it loads the businesscontext file and as well as the domain context file and works fine ..</p> <p>3)In my service module i have the similar stuff my service impl code looks like the following</p> <p>@Component public class ServiceImpl implements Service {</p> <pre><code> @Autowired private ItemPricingManager itemPricingManager; </code></pre> <p>}</p> <p>and then in context file looks like the following</p> <pre><code> &lt;beans&gt; &lt;context:component-scan base-package="basepackage" /&gt; &lt;/beans&gt; </code></pre> <p>in my test i do the following</p> <pre><code>@ContextConfiguration(locations = { "classpath:GenericContext.xml" }) public class ServiceTest extends AbstractTestNGSpringContextTests { @Autowired Service mgr; } </code></pre> <p>This context file should load three context files like service,business and also the domain and when it should create the DALCOnfigLoader bean first because this is the one which has the configuration things and its being depend on the DAOImpl class but when i run here it does not load the mgr and it fails .. it mainly fails because the root bean which loads the configuration file is not laoding ... So not sure what can fix this..and i am not sure in what order the beans are creating or it should create.. my understanding is that it should crate the inner most bean which has a depends on DALConfigLoader which should load the confugration file.. its not happening ...I am not sure what went wrong...</p> <p>The exception what i get is</p> <p>java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157) and at the end Caused by: java.lang.NullPointerException</p> <p>This is happening because the intial bean is not laoded which is what has the stuff defined.. The test looks like the following</p> <pre><code>@ContextConfiguration(locations = {"classpath:GenericContext.xml"}) public class ItemPricingServiceImplTest extends AbstractTestNGSpringContextTests{ @Autowired private IService itemPricingSer; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload