package edu.neu.cloudaddy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
import org.thymeleaf.templateresolver.TemplateResolver;

@EnableWebMvc
@Configuration
@ComponentScan(basePackages = "edu.neu.cloudaddy")
@Import({ WebSecurityConfig.class })
public class AppConfig  extends WebMvcConfigurerAdapter{
	private static final String TEMPLATE_RESOLVER_PREFIX = "/resource/templates/";
    private static final String TEMPLATE_RESOLVER_SUFFIX = ".html";
    private static final String TEMPLATE_RESOLVER_TEMPLATE_MODE = "HTML5";
	
	@Bean(name = "dataSource")
	public DriverManagerDataSource dataSource() {
	    DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
	    driverManagerDataSource.setDriverClassName("com.mysql.jdbc.Driver");
	    driverManagerDataSource.setUrl("jdbc:mysql://localhost:3306/clouddaddy");
	    driverManagerDataSource.setUsername("root");
	    driverManagerDataSource.setPassword("admin");
	    return driverManagerDataSource;
	}
	
	 @Bean
	    public ViewResolver viewResolver() {
	        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
	        viewResolver.setTemplateEngine((SpringTemplateEngine) templateEngine());

	        return viewResolver;
	    }

	    @Bean
	    public TemplateEngine templateEngine() {
	        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
	        templateEngine.setTemplateResolver(templateResolver());

	        return templateEngine;
	    }

	    @Bean
	    public TemplateResolver templateResolver() {
	        TemplateResolver templateResolver = new ServletContextTemplateResolver();
	        templateResolver.setPrefix(TEMPLATE_RESOLVER_PREFIX);
	        templateResolver.setSuffix(TEMPLATE_RESOLVER_SUFFIX);
	        templateResolver.setTemplateMode(TEMPLATE_RESOLVER_TEMPLATE_MODE);

	        return templateResolver;
	    }
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/resources/**").addResourceLocations("/resources/") .setCachePeriod(31556926);
		registry.addResourceHandler("/assets/**").addResourceLocations("/assets/");
	    registry.addResourceHandler("/css/**").addResourceLocations("/css/");
	    registry.addResourceHandler("/img/**").addResourceLocations("/img/");
	}
	   
}

@@ -28,16 +28,75 @@
 onfig;%0A%0A
+import org.springframework.beans.factory.annotation.Value;%0A
 import o
@@ -135,24 +135,24 @@
 ation.Bean;%0A
-
 import org.s
@@ -315,16 +315,78 @@
 Import;%0A
+import org.springframework.context.annotation.PropertySource;%0A
 import o
@@ -1085,16 +1085,68 @@
 daddy%22)%0A
+@PropertySource(%22classpath:application.properties%22)%0A
 @Import(
@@ -1456,16 +1456,208 @@
 ML5%22;%0A%09%0A
+    @Value(%22$%7BmySql.url%7D%22)%0A%09private String mysqlUrl;%0A    %0A    @Value(%22$%7BmySql.username%7D%22)%0A%09private String mysqlUsername;%0A    %0A    @Value(%22$%7BmySql.password%7D%22)%0A%09private String password;%0A  %0A    %0A
 %09@Bean(n
@@ -1923,48 +1923,16 @@
 Url(
-%22jdbc:mysql://localhost:3306/clouddaddy%22
+mysqlUrl
 );%0A%09
@@ -1975,14 +1975,21 @@
 ame(
-%22root%22
+mysqlUsername
 );%0A%09
@@ -2032,15 +2032,16 @@
 ord(
-%22admin%22
+password
 );%0A%09

add appconfig