Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1.  
  2. @SpringBootApplication
  3. @Slf4j
  4. public class Application {
  5.     @Entity
  6.     @Data
  7.     static class MyEntity {
  8.         @Id
  9.         @GeneratedValue
  10.         private String id;
  11.     }
  12.  
  13.     @Repository
  14.     interface MyDao extends JpaRepository<MyEntity, String> {
  15.  
  16.     }
  17.  
  18.     @RequiredArgsConstructor
  19.     @Component
  20.     class MyService {
  21.         private final MyDao dao;
  22.         public void someMethod(){}
  23.     }
  24.  
  25.     @RequiredArgsConstructor
  26.     @Transactional
  27.     @Component
  28.     static class MyTransactedService {
  29.         private final MyDao dao;
  30.         public void someMethod(){}
  31.     }
  32.  
  33.     @Controller
  34.     @RequiredArgsConstructor
  35.     @Getter
  36.     static class MyController {
  37.         private final MyService myService;
  38.         private final MyTransactedService myTransactedService;
  39.     }
  40.  
  41.     public static void main(String[] args) {
  42.         ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
  43.         MyController myController = context.getBean(MyController.class);
  44.         MyService myService = myController.getMyService();
  45.         MyTransactedService myTransactedService = myController.getMyTransactedService();
  46.         log.info("myController bean class: {}", myController.getClass());
  47.         log.info("myService bean class: {}", myService.getClass());
  48.         log.info("myTransactedService bean class: {}", myTransactedService.getClass());
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement