• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoSuchBeanDefinitionException using spring and mybatis

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Let me try it out ...
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic