Starting the Application

After creating the entity and repository, you should write a program to run the Spring application. You can do that using a Spring boot application or a Spring core application.

Create an @SpringBootApplication annotated class to run a Spring boot application. You could override the run method in the CommandLineRunner interface to write your code.

The following is an example of a Spring boot application.

//The annotation helps to build an application using Spring Data Framework rapidly.
@SpringBootApplication
public class BootExample implements CommandLineRunner {

    /*The annotation enables Spring Data Framework to 
      look up the configuration file for a matching bean.*/
    @Autowired
    private StudentRepository nosqlRepo;

    @Override
    public void run(String... args) throws Exception {
        ...
    }
}

The following is an example of a Spring core application.

public class CoreExample {
    public static void main(String[] args) {
        ApplicationContext ctx =
            new AnnotationConfigApplicationContext(AppConfig.class);
        NosqlOperations ops = (NosqlOperations)ctx.getBean("nosqlTemplate");
        ...
    }
}

Note:

The Spring Data Framework will look in the classpath for a class with the @configuration annotation and contains a method named "NosqlTemplate" with the @Bean annotation.