添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

We've opened a new role Backend Java/Spring Team Lead with Integration Experience . Part-time and entirely remote, of course.

Read More

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

An in-depth piece exploring building a modular event-driven microservices architecture, using Spring and Orkes Conductor for orchestration:

Event-Driven Microservices With Orkes Conductor

Partner – Aegik AB – NPI EA (cat=JPA)
announcement - icon

Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.

The Jet Profiler was built for MySQL only , so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.

Critically, it has very minimal impact on your server's performance, with most of the profiling work done separately - so it needs no server changes, agents or separate services.

Basically, you install the desktop application, connect to your MySQL server , hit the record button, and you'll have results within minutes:

out the Profiler

Partner – Microsoft – NPI EA (cat=Java)
announcement - icon

Microsoft JDConf 2024 conference is getting closer, on March 27th and 28th. Simply put, it's a free virtual event to learn about the newest developments in Java, Cloud, and AI.

Josh Long and Mark Heckler are kicking things off in the keynote, so it's definitely going to be both highly useful and quite practical.

This year’s theme is focused on developer productivity and how these technologies transform how we work, build, integrate, and modernize applications.

For the full conference agenda and speaker lineup, you can explore JDConf.com:

RSVP Now

Partner – Payara – NPI EA (cat=JAVA EE)
announcement - icon

Accelerate Your Jakarta EE Development with Payara Server!

With best-in-class guides and documentation, Payara essentially simplifies deployment to diverse infrastructures.

Beyond that, it provides intelligent insights and actions to optimize Jakarta EE applications.

The goal is to apply an opinionated approach to get to what's essential for mission-critical applications - really solid scalability, availability, security, and long-term support:

>> Download and Explore the Guide (to learn more)

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

Course – RwS – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> REST With Spring (new)

Course – LS – NPI EA (cat=Spring)
announcement - icon

Get started with Spring and Spring Boot, through the reference Learn Spring course:

>> LEARN SPRING

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Partner – Machinet – NPI EA (cat = Testing)
announcement - icon

The AI Assistant to boost Boost your productivity writing unit tests - Machinet AI .

AI is all the rage these days, but for very good reason. The highly practical coding companion, you'll get the power of AI-assisted coding and automated unit test generation .
Machinet's Unit Test AI Agent utilizes your own project context to create meaningful unit tests that intelligently aligns with the behavior of the code.
And, the AI Chat crafts code and fixes errors with ease, like a helpful sidekick.

Simplify Your Coding Journey with Machinet AI :

>> Install Machinet AI in your IntelliJ

Partner – Codium – NPI EA (cat = Testing)
announcement - icon

Get non-trivial analysis (and trivial, too!) suggested right inside your IDE or Git platform so you can code smart, create more value, and stay confident when you push.

Get CodiumAI for free and become part of a community of over 280,000 developers who are already experiencing improved and quicker coding.

Write code that works the way you meant it to:

CodiumAI. Meaningful Code Tests for Busy Devs

Partner – Bellsoft – NPI EA (cat = Spring)
announcement - icon

Looking for the ideal Linux distro for running modern Spring apps in the cloud?

Meet Alpaquita Linux : lightweight, secure, and powerful enough to handle heavy workloads.

This distro is specifically designed for running Java apps . It builds upon Alpine and features significant enhancements to excel in high-density container environments while meeting enterprise-grade security standards.

Specifically, the container image size is ~30% smaller than standard options, and it consumes up to 30% less RAM:

Alpaquita Containers now.

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth , to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project .

You can explore the course here:

>> Learn Spring Security

Partner – Aegik AB – NPI EA (tag = SQL)
announcement - icon

Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.

The Jet Profiler was built for MySQL only , so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.

Critically, it has very minimal impact on your server's performance, with most of the profiling work done separately - so it needs no server changes, agents or separate services.

Basically, you install the desktop application, connect to your MySQL server , hit the record button, and you'll have results within minutes:

out the Profiler

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot .

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – MongoDB – NPI EA (tag=MongoDB)
announcement - icon

Just published a deep dive into building a relevance-focused search with MongoDB. More or less out of the box:

>> MongoDB Atlas Search

Partner – Expected Behavior – NPI EA (tag=PDF)
announcement - icon

Creating PDFs is actually surprisingly hard. When we first tried, none of the existing PDF libraries met our needs. So we made DocRaptor for ourselves and later launched it as one of the first HTML-to-PDF APIs.

We think DocRaptor is the fastest and most scalable way to make PDFs , especially high-quality or complex PDFs. And as developers ourselves, we love good documentation, no-account trial keys, and an easy setup process.

>> Try DocRaptor's HTML-to-PDF Java Client (No Signup Required)

1. Overview

In this tutorial, we discuss the Spring org.springframework.beans.factory.NoSuchBeanDefinitionException .

This is a common exception thrown by the BeanFactory when trying to resolve a bean that simply isn’t defined in the Spring Context.

We’ll illustrate the possible causes for this problem and the available solutions.

And of course, exceptions happen when we least expect them, so have a look at the full list of exceptions and solutions in Spring .

Further reading:

Some of the most common exceptions in Spring with examples - why they occur and how to solve them quickly.
Read more → A quick and practical guide to dealing with different causes of Spring BeanCreationException
Read more → //...

Now if the dependency BeanB is not defined in the Spring Context, the bootstrap process will fail with the no such bean definition exception :

org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [com.baeldung.packageB.BeanB]
  found for dependency: 
expected at least 1 bean which qualifies as
  autowire candidate for this dependency. 
Dependency annotations: 
  {@org.springframework.beans.factory.annotation.Autowired(required=true)}

The reason is clearly indicated by Spring: expected at least 1 bean which qualifies as autowire candidate for this dependency .

One reason BeanB may not exist in the context — if beans are picked up automatically by classpath scanning , and if BeanB is correctly annotated as a bean ( @Component , @Repository , @Service , @Controller , etc.) — is that it may be defined in a package that is not scanned by Spring :

package com.baeldung.packageB;
@Component
public class BeanB { ...}

And the classpath scanning may be configured as follows:

@Configuration
@ComponentScan("com.baeldung.packageA")
public class ContextWithJavaConfig {

If beans are not automatically scanned but instead defined manually, then BeanB is simply not defined in the current Spring Context.

3. Cause: Field […] in […] Required a Bean of Type […] That Could Not Be Found

In a Spring Boot application for the above scenario, we get a different message.

Let’s take the same example where BeanB is wired in BeanA, but it’s not defined:

@Component
public class BeanA {
    @Autowired
    private BeanB dependency;
    //...

If we try to run this simple application, that tries to load BeanA:

@SpringBootApplication
public class NoSuchBeanDefinitionDemoApp {
    public static void main(String[] args) {
        SpringApplication.run(NoSuchBeanDefinitionDemoApp.class, args);

The application will fail to start with this error message:

***************************
APPLICATION FAILED TO START
***************************
Description:
Field dependency in com.baeldung.springbootmvc.nosuchbeandefinitionexception.BeanA required a bean of type 'com.baeldung.springbootmvc.nosuchbeandefinitionexception.BeanB' that could not be found.
Action:
Consider defining a bean of type 'com.baeldung.springbootmvc.nosuchbeandefinitionexception.BeanB' in your configuration.

Here com.baeldung.springbootmvc.nosuchbeandefinitionexception is the package for BeanA, BeanB and NoSuchBeanDefinitionDemoApp.

The snippet for this example can be found in this GitHub project.

4. Cause: No Qualifying Bean of Type […] Is Defined

Another cause for the exception is the existence of two bean definitions in the context, instead of one.

Let’s say an interface IBeanB is implemented by two beans, BeanB1 and BeanB2:

@Component
public class BeanB1 implements IBeanB {
@Component
public class BeanB2 implements IBeanB {

Now if BeanA autowires this interface, Spring will not know which one of the two implementations to inject:

@Component
public class BeanA {
    @Autowired
    private IBeanB dependency;

And again, this will result in a NoSuchBeanDefinitionException being thrown by the BeanFactory:

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: 
No qualifying bean of type 
  [com.baeldung.packageB.IBeanB] is defined: 
expected single matching bean but found 2: beanB1,beanB2

Similarly, Spring clearly indicates the reason for the wiring failure: expected single matching bean but found 2.

However, notice that in this case the exact exception being thrown is not NoSuchBeanDefinitionException but a subclass: the NoUniqueBeanDefinitionException. This new exception was introduced in Spring 3.2.1 for exactly this reason — to differentiate between the cause where no bean definition was found and where several definitions are found in the context.

Before this change, this was the above exception:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [com.baeldung.packageB.IBeanB] is defined: 
expected single matching bean but found 2: beanB1,beanB2

One solution to this problem is to use the @Qualifier annotation to specify exactly the name of the bean we want to wire:

@Component
public class BeanA {
    @Autowired
    @Qualifier("beanB2")
    private IBeanB dependency;

Now Spring has enough information to make the decision of which bean to inject — BeanB1 or BeanB2 (the default name of BeanB2 is beanB2).

5. Cause: No Bean Named […] Is Defined

A NoSuchBeanDefinitionException may also be thrown when a bean that isn’t defined is requested by name from the Spring context:

@Component
public class BeanA implements InitializingBean {
    @Autowired
    private ApplicationContext context;
    @Override
    public void afterPropertiesSet() {
        context.getBean("someBeanName");

In this case, there is no bean definition for “someBeanName”, leading to the following exception:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No bean named 'someBeanName' is defined

Again, Spring clearly and concisely indicates the reason for the failure: No bean named X is defined.

6. Cause: Proxied Beans

When a bean in the context is proxied using the JDK Dynamic Proxy mechanism, the proxy will not extend the target bean (but it will implement the same interfaces).

Because of this, if the bean is injected by an interface, it will be correctly wired in. However, if the bean is injected by the actual class, Spring will not find a bean definition that matches the class since the proxy does not actually extend the class.

A very common reason the bean may be proxied is the Spring transactional support, namely beans that are annotated with @Transactional.

For example, if ServiceA injects ServiceB, and both services are transactional, injecting by the class definition will not work:

@Service
@Transactional
public class ServiceA implements IServiceA{
    @Autowired
    private ServiceB serviceB;
@Service
@Transactional
public class ServiceB implements IServiceB{

The same two services, this time correctly injecting by the interface, will be okay:

@Service
@Transactional
public class ServiceA implements IServiceA{
    @Autowired
    private IServiceB serviceB;
@Service
@Transactional
public class ServiceB implements IServiceB{

7. Conclusion

This article discussed examples of the possible causes for the common NoSuchBeanDefinitionException — with a focus on how to address these exceptions in practice.

The implementation of all these exceptions examples can be found in the GitHub project. This is an Eclipse-based project, so it should be easy to import and run as it is.

Finally, the full list of exceptions and solutions in Spring might be a good resource to bookmark.

Partner – Microsoft – NPI EA (cat=Java)
announcement - icon

Microsoft JDConf 2024 conference is getting closer, on March 27th and 28th. Simply put, it's a free virtual event to learn about the newest developments in Java, Cloud, and AI.

Josh Long and Mark Heckler are kicking things off in the keynote, so it's definitely going to be both highly useful and quite practical.

For the full conference agenda and speaker lineup, you can explore JDConf.com:

RSVP Now

Partner – Payara – NPI EA (cat=Jakarta EE)
announcement - icon

Can Jakarta EE be used to develop microservices? The answer is a resounding ‘yes’!

Demystifying Microservices for Jakarta EE & Java EE Developers

Partner – Aegik AB – NPI EA (tag = SQL)
announcement - icon

Slow MySQL query performance is all too common. Of course it is.

The Jet Profiler was built entirely for MySQL, so it's fine-tuned for it and does advanced everything with relaly minimal impact and no server changes.

out the Profiler

Partner – Codium – NPI EA (cat = Testing)
announcement - icon

Explore the secure, reliable, and high-performance Test Execution Cloud built for scale. Right in your IDE:

CodiumAI. Meaningful Code Tests for Busy Devs

Basically, write code that works the way you meant it to.

Partner – Machinet – NPI EA (cat = Testing)
announcement - icon

AI is all the rage these days, but for very good reason. The highly practical coding companion, you'll get the power of AI-assisted coding and automated unit test generation.
Machinet's Unit Test AI Agent utilizes your own project context to create meaningful unit tests that intelligently aligns with the behavior of the code.

Simplify Your Coding Journey with Machinet AI:

>> Install Machinet AI in your IntelliJ

Course – LS (cat=Spring)

Get started with Spring and Spring Boot, through the Learn Spring course:

>> THE COURSE
res – REST with Spring (eBook) (everywhere)