While I was using XML based configuration, I came across java file based configuration,when implemented I am facing issues in the code.

The project is just an example to understand the usage of Java Based Configuration file.

Here is it's architecture:

enter image description here

HelloWorld.java file is as follows :

public class HelloWorld {
 private String message;

   public void setMessage(String message){
      this.message  = message;
   }
   public void getMessage(){
      System.out.println("Your Message : " + message);
   }
}

HelloWorldConfig.java files is as follows :

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HelloWorldConfig {

  @Bean 
   public HelloWorld helloWorld(){
      return new HelloWorld();
   }
}

MainApp.java is as follows :

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
public class MainApp {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    ApplicationContext ctx = new 
      AnnotationConfigApplicationContext(HelloWorldConfig.class);

      HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
      helloWorld.setMessage("Hello World!");
      helloWorld.getMessage();
    }
}

When I am running the MainApp.java as JavaApplication it results in following error : enter image description here

Please help me in knowing what has been missed. Let me know if more information is required.

0

There are 0 best solutions below