Search in sources :

Example 1 with BookService

use of com.tvd12.example.spring_boot.service.BookService in project java-examples by tvd12.

the class MyApplicationStartup method main.

public static void main(String[] args) {
    ApplicationContext appContext = SpringApplication.run(MyApplicationStartup.class, args);
    BookService bookService = appContext.getBean(BookService.class);
    bookService.saveBook(new Book(1, "youngmonkeys.org"));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Book(com.tvd12.example.spring_boot.entity.Book) BookService(com.tvd12.example.spring_boot.service.BookService)

Example 2 with BookService

use of com.tvd12.example.spring_boot.service.BookService in project java-examples by tvd12.

the class ApplicationContextExample method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.scan("com.tvd12.example.spring_core.config");
    context.scan("com.tvd12.example.spring_core.repo");
    context.scan("com.tvd12.example.spring_core.service");
    context.refresh();
    BookService bookService = context.getBean(BookService.class);
    System.out.println(bookService.getBookById(1));
    Environment environment = context.getEnvironment();
    String world = environment.getProperty("hello");
    System.out.println(world);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) BookService(com.tvd12.example.spring_core.service.BookService) Environment(org.springframework.core.env.Environment)

Aggregations

Book (com.tvd12.example.spring_boot.entity.Book)1 BookService (com.tvd12.example.spring_boot.service.BookService)1 BookService (com.tvd12.example.spring_core.service.BookService)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Environment (org.springframework.core.env.Environment)1