0

I have written a small Spring (Version 4) application using @Component, @ComponentScan annotation as below.

Configuration class

@Configuration
@ComponentScan
public class DiskConfig {
}

Bean Class

@Component
public class BlankDisk implements Disk {

    private String title;
    private String artist;

    public BlankDisk(){}

    public BlankDisk(@Value("${disk.title}") String title, @Value("${disk.artist}") String artist) {

        this.title = title;
        this.artist = artist;
    }

    @Override
    public void play() {

        System.out.println("The artist " + artist + " is playing the title " + title);
    }

}


@Component
public class AutowireDemo {

    @Autowired
    private BlankDisk blankDisk;

    public void play() {

        blankDisk.play();
    }

}

In the play() method I am getting NullPointerException. The framework couldn't create the BlankDisk instance.

I am very new to Spring. Can anyone help me how to resolve this issue?

Java-Seekar
  • 1,720
  • 5
  • 30
  • 52

0 Answers0