wood burning stoves 2.0*
The moose likes Spring and the fly likes NoSuchBeanDefinitionException using spring and mybatis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "NoSuchBeanDefinitionException using spring and mybatis" Watch "NoSuchBeanDefinitionException using spring and mybatis" New topic
Author

NoSuchBeanDefinitionException using spring and mybatis

J amodi
Greenhorn

Joined: Nov 09, 2011
Posts: 18
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 ?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
J amodi
Greenhorn

Joined: Nov 09, 2011
Posts: 18
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
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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

Joined: Nov 09, 2011
Posts: 18
Ok. Let me try it out ...
 
Consider Paul's rocket mass heater.
 
subject: NoSuchBeanDefinitionException using spring and mybatis