]> git.somenet.org - pub/jan/dst18.git/blob - ass2-service/auth/src/test/java/dst/ass2/service/auth/SpringGrpcServerRunner.java
Add template for assignment 2
[pub/jan/dst18.git] / ass2-service / auth / src / test / java / dst / ass2 / service / auth / SpringGrpcServerRunner.java
1 package dst.ass2.service.auth;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.springframework.boot.CommandLineRunner;
6 import org.springframework.context.ApplicationContext;
7 import org.springframework.context.ApplicationContextAware;
8
9 import dst.ass2.service.auth.grpc.IGrpcServerRunner;
10
11 /**
12  * This class loads the {@link IGrpcServerRunner} from the application context and runs it after the application starts.
13  */
14 public class SpringGrpcServerRunner implements CommandLineRunner, ApplicationContextAware {
15
16     private static final Logger LOG = LoggerFactory.getLogger(SpringGrpcServerRunner.class);
17
18     private ApplicationContext applicationContext;
19
20     @Override
21     public void setApplicationContext(ApplicationContext applicationContext) {
22         this.applicationContext = applicationContext;
23     }
24
25     @Override
26     public void run(String... args) throws Exception {
27         LOG.info("Getting instance of GrpcServerRunner");
28         IGrpcServerRunner bean = applicationContext.getBean(IGrpcServerRunner.class);
29         LOG.info("Starting IGrpcServerRunner instance {}", bean);
30         bean.run();
31     }
32 }