• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

@Autowire is not working properly in my spring application

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
my service implementation class is marked as @Service and my controller class as @Controller,
and i have @Autowired
private FruitService fruitService; in my controller class. and getters and setters of the same. but when i try to acesss fruitService through getter methos i am getting classnotfound exception. can any body tell me what might have went wrong.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If autowiring doesn't work, I'd expect a NullPointerException, as it means a property you were expecting to be set wasn't.

ClassNotFoundException is different than NullPointerException - it means there's a class referenced in your code that your web application can't find. This could be due to multiple things - a mis-spelling of a class name in a deployment descriptor or spring xml file, a packaging issue where the class doesn't get included in the deployment, or a classpath issue.
 
prathibha shiju
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes that was nullpointer exception. but still i could not corre t that.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Have you enabled annotation configuration?



2. Do you have multiple beans that implement FruitService defined?
DZone article discussing multiple beans and autowiring problems.

3. You mentioned you have both the attribute and the getter/setter methods tagged with the @Autowire attribute... you should only need to do this in one or the other.

4. Are the parameters of the getter/setter methods and the attribute the same class?
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!