package com.samsung.config;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.apache.tomcat.util.descriptor.web.ContextResource;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;


@Configuration
@Profile("dev")
public class TomcatEmbdded {
	@Bean
	public TomcatServletWebServerFactory tomcatFactory() {
	    return new TomcatServletWebServerFactory() {
	        @Override
	        protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
	            tomcat.enableNaming(); 
	            return super.getTomcatWebServer(tomcat);
	        }

	        @Override 
	        protected void postProcessContext(Context context) {
	        	ContextResource resource1 = new ContextResource();

	        	resource1.setName("sdl_ds");
	        	resource1.setAuth("Container");
	        	resource1.setProperty("factory", "org.apache.commons.dbcp2.BasicDataSourceFactory");
	        	resource1.setType("javax.sql.DataSource");
	        	resource1.setProperty("driverClassName", "net.sf.log4jdbc.sql.jdbcapi.DriverSpy");

	        	resource1.setProperty("url", "jdbc:log4jdbc:sqlserver://localhost:1333;database=embo;encrypt=false;trustServerCertificate=true;");
	        	resource1.setProperty("username", "sa");
	        	resource1.setProperty("password", "qazwsx12##");
	        	
	        	
	            context.getNamingResources().addResource(resource1); 
	        }
	    };
	}
}
