Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

NoSuchBeanDefinitionException using spring and mybatis

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am getting below error when I create application using spring mvc, mybatis and maven



Please find my code..

TeacherController.java


TeacherService.java




TeacherMapper.java





Could anyone tell me what am I doing wrong ?
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it isn't seeing your Service classes.

What my guess would be is that you aren't setting it up correctly with 2 ApplicationContexts, which is typical in a Spring MVC app.

So the DispatcherServlet servlet creates a child application context, this should have beans that are for the Web Layer only. No Services or below in this config.

The ContextLoaderListener creates a parent application context. This should have your middle tier beans only. Services and below.

With this setup in the web.xml, then the child app context can see all thebeans in the parent app context.

So my guess is you deployed the DispatcherServlet pointing to the config file for the Web Tier beans, which is correct. But you didn't configure the ContextLoaderListener in your web.xml

Post your web.xml

Mark
 
J amodi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Well, it isn't seeing your Service classes.

What my guess would be is that you aren't setting it up correctly with 2 ApplicationContexts, which is typical in a Spring MVC app.

So the DispatcherServlet servlet creates a child application context, this should have beans that are for the Web Layer only. No Services or below in this config.

The ContextLoaderListener creates a parent application context. This should have your middle tier beans only. Services and below.

With this setup in the web.xml, then the child app context can see all thebeans in the parent app context.

So my guess is you deployed the DispatcherServlet pointing to the config file for the Web Tier beans, which is correct. But you didn't configure the ContextLoaderListener in your web.xml

Post your web.xml

Mark




Hi ..

Thanks for the reply. Please find web.xml. Let me know where and what am I doing wrong ?

 
Mark Spritzler
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two context-params. The first one is for the ContextLoaderListener and is correct. Although if that is the file you have in your WEB-INF with that name, then you don't need the context-param for it, that is the default location and name.

As far as your second one. That is supposed to be used for your DispatcherServlet, which should be in your <servlet> tag as an <init-param>

But again, for that init-param, you name it also following the naming default strategy, so you wouldn't even need it either. If that is the location and name of that config file.

So my recommendation first.

Remove both <context-param> that you have in your web.xml and try it out.

Mark
 
J amodi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Let me try it out ...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!