Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructor based dependency injection  RSS feed

 
Suhaas Mohandos
Greenhorn
Posts: 21
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying out  a basic example of constructor based dependency injection.

I am getting the following error:

Aug 03, 2016 5:45:09 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@29104a: startup date [Wed Aug 03 17:45:09 IST 2016]; root of context hierarchy
Aug 03, 2016 5:45:09 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Aug 03, 2016 5:45:09 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a03464: defining beans [spellChecker,textEditor]; root of factory hierarchy
Inside spell checker constructor
Exception in thread "main" java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass(LocalVariableTableParameterNameDiscoverer.java:112)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:86)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:193)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1049)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:953)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.tutorialspoint.MainApp.main(MainApp.java:9)

Files:






 
AsifM Sheikh
Greenhorn
Posts: 6
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suhass,

I have tried your example without any modification and it's working fine.Can you please check your project hierarchy.
May be there is some issue with that.
 
Suhaas Mohandos
Greenhorn
Posts: 21
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I believe I have the correct project structure.

I have created a Java project. Created Beans.xml in src folder and created the packages and classes in src folder.

I have attached a screenshot of the project structure
errorConstructorDI.png
[Thumbnail for errorConstructorDI.png]
Project Structure Constructor DI
 
AsifM Sheikh
Greenhorn
Posts: 6
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suhass,

Please paste the Bean.XML file in the src folder.Currently it's in your package folder.
Once you move that your program will run.
 
Suhaas Mohandos
Greenhorn
Posts: 21
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Beans.xml is in src folder only.

Please see screenshot
1.png
[Thumbnail for 1.png]
 
AsifM Sheikh
Greenhorn
Posts: 6
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your java version and Spring?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!