Coverage Report - com.ctrip.framework.apollo.portal.configutation.ServletContextConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
ServletContextConfiguration
0%
0/2
N/A
2.5
ServletContextConfiguration$1
0%
0/8
0%
0/6
2.5
 
 1  
 package com.ctrip.framework.apollo.portal.configutation;
 2  
 
 3  
 import com.ctrip.framework.apollo.portal.entity.po.ServerConfig;
 4  
 import com.ctrip.framework.apollo.portal.repository.ServerConfigRepository;
 5  
 
 6  
 import org.springframework.beans.factory.annotation.Autowired;
 7  
 import org.springframework.boot.context.embedded.ServletContextInitializer;
 8  
 import org.springframework.context.annotation.Bean;
 9  
 import org.springframework.context.annotation.Configuration;
 10  
 import org.springframework.context.annotation.Profile;
 11  
 
 12  
 import javax.servlet.ServletContext;
 13  
 import javax.servlet.ServletException;
 14  
 
 15  
 @Configuration
 16  
 @Profile("ctrip")
 17  0
 public class ServletContextConfiguration {
 18  
 
 19  
   @Autowired
 20  
   private ServerConfigRepository serverConfigRepository;
 21  
 
 22  
   @Bean
 23  
   public ServletContextInitializer initializer(){
 24  
 
 25  0
     return new ServletContextInitializer() {
 26  
 
 27  
       @Override
 28  
       public void onStartup(ServletContext servletContext) throws ServletException {
 29  0
         ServerConfig loggingServerIP = serverConfigRepository.findByKey("loggingServerIP");
 30  0
         ServerConfig loggingServerPort = serverConfigRepository.findByKey("loggingServerPort");
 31  0
         ServerConfig credisServiceUrl = serverConfigRepository.findByKey("credisServiceUrl");
 32  0
         servletContext.setInitParameter("loggingServerIP", loggingServerIP == null ? "" :loggingServerIP.getValue());
 33  0
         servletContext.setInitParameter("loggingServerPort", loggingServerPort == null ? "" :loggingServerPort.getValue());
 34  0
         servletContext.setInitParameter("credisServiceUrl", credisServiceUrl == null ? "" :credisServiceUrl.getValue());
 35  0
       }
 36  
     };
 37  
   }
 38  
 
 39  
 }