| |

VerySource

 Forgot password?
 Register
Search
View: 813|Reply: 4

How to solve NoSuchBeanDefinitionException?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-13 16:00:01
| Show all posts |Read mode
<listener>
        <listener-class> org.springframework.web.context.ContextLoaderListener <stener-class>
    <stener>
    <listener>
    <listener-class> cn.edu.buaa.iegsa.server.EventInterceptorListener <stener-class>
    <stener>

Use in EventInterceptorListener:
ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext (event.getServletContext ());
applicationContext.getBean ("dataSource");

How can I not get javabean? The error that appears is:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-9 23:15:01
| Show all posts
Paste your spring configuration file and see
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 United States

Post time: 2020-6-10 07:15:01
| Show all posts
Check if the bean with the name dataSource is configured in the spring configuration file.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-10 19:30:01
| Show all posts
Certainly there is no shortage, because when the web server is started, I run the main function in the java file to get ApplicationContext applicationContext=WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
applicationContext.getBean("dataSource");

It is normal, the reason may be said: In the web environment, when the EventInterceptorListener runs the above code, the xml configuration file system has not been initialized.

What do you think?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-3 19:30:01
| Show all posts
There should be a problem in other DAO classes or Service classes!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list