11package org .woehlke .simpleworklist .config .di ;
22
3+ import org .springframework .beans .factory .annotation .Autowired ;
34import org .springframework .boot .autoconfigure .ImportAutoConfiguration ;
45import org .springframework .boot .context .properties .EnableConfigurationProperties ;
56import org .springframework .context .MessageSource ;
67import org .springframework .context .annotation .Bean ;
78import org .springframework .context .annotation .Configuration ;
89import org .springframework .context .support .ResourceBundleMessageSource ;
910import org .springframework .data .jpa .repository .config .EnableJpaAuditing ;
11+ import org .springframework .data .jpa .repository .config .EnableJpaRepositories ;
1012import org .springframework .data .web .config .EnableSpringDataWebSupport ;
13+ import org .springframework .mail .javamail .JavaMailSender ;
14+ import org .springframework .mail .javamail .JavaMailSenderImpl ;
1115import org .springframework .scheduling .annotation .EnableAsync ;
1216import org .springframework .session .jdbc .config .annotation .web .http .EnableJdbcHttpSession ;
1317import org .springframework .validation .beanvalidation .MethodValidationPostProcessor ;
1923import org .woehlke .simpleworklist .config .ApplicationProperties ;
2024
2125import java .util .Locale ;
26+ import java .util .Properties ;
2227
2328
2429@ Configuration
2732@ EnableWebMvc
2833@ EnableSpringDataWebSupport
2934@ EnableJdbcHttpSession
30- @ ImportAutoConfiguration ({
31- ApplicationConfig . class
35+ @ EnableJpaRepositories ({
36+ "org.woehlke.simpleworklist"
3237})
3338@ EnableConfigurationProperties ({
3439 ApplicationProperties .class
3540})
3641public class WebMvcConfig extends WebMvcConfigurerAdapter implements WebMvcConfigurer {
3742
43+ private final ApplicationProperties applicationProperties ;
44+
45+ @ Autowired
46+ public WebMvcConfig (ApplicationProperties applicationProperties ) {
47+ this .applicationProperties = applicationProperties ;
48+ }
49+
50+ @ Bean
51+ public JavaMailSender mailSender (){
52+ Properties javaMailProperties = new Properties ();
53+ javaMailProperties .setProperty (
54+ "mail.smtp.auth" ,
55+ applicationProperties .getMail ().getAuth ().toString ()
56+ );
57+ javaMailProperties .setProperty (
58+ "mail.smtp.ssl.enable" ,
59+ applicationProperties .getMail ().getSslEnable ().toString ()
60+ );
61+ javaMailProperties .setProperty (
62+ "mail.smtp.socketFactory.port" ,
63+ applicationProperties .getMail ().getSocketFactoryPort ()
64+ );
65+ javaMailProperties .setProperty (
66+ "mail.smtp.socketFactory.class" ,
67+ applicationProperties .getMail ().getSocketFactoryClass ()
68+ );
69+ JavaMailSenderImpl mailSender = new JavaMailSenderImpl ();
70+ mailSender .setJavaMailProperties (javaMailProperties );
71+ mailSender .setHost (applicationProperties .getMail ().getHost ());
72+ mailSender .setPort (applicationProperties .getMail ().getPort ());
73+ mailSender .setUsername (applicationProperties .getMail ().getUsername ());
74+ mailSender .setPassword (applicationProperties .getMail ().getPassword ());
75+ return mailSender ;
76+ }
77+
3878 @ Bean
3979 public LocaleResolver localeResolver () {
4080 SessionLocaleResolver slr = new SessionLocaleResolver ();
@@ -51,9 +91,9 @@ public LocaleChangeInterceptor localeChangeInterceptor() {
5191
5292 @ Bean
5393 public MessageSource messageSource (){
54- ResourceBundleMessageSource x = new ResourceBundleMessageSource ();
55- x .setBasename ("messages" );
56- return x ;
94+ ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource ();
95+ messageSource .setBasename ("messages" );
96+ return messageSource ;
5797 }
5898
5999 @ Bean
@@ -76,13 +116,15 @@ public void addViewControllers(ViewControllerRegistry registry) {
76116 }
77117
78118 public void addResourceHandlers (ResourceHandlerRegistry registry ) {
79- registry .addResourceHandler ("/css/*" ).addResourceLocations ("classpath:/static/css/" );
80- registry .addResourceHandler ("/css/**" ).addResourceLocations ("classpath:/static/css/" );
81- registry .addResourceHandler ("/img/*" ).addResourceLocations ("classpath:/static/img/" );
82- registry .addResourceHandler ("/img/**" ).addResourceLocations ("classpath:/static/img/" );
83- registry .addResourceHandler ("/js/*" ).addResourceLocations ("classpath:/static/js/" );
84- registry .addResourceHandler ("/js/**" ).addResourceLocations ("classpath:/static/js/" );
85- registry .addResourceHandler ("/webjars/*" ).addResourceLocations ("/webjars/" );
86- registry .addResourceHandler ("/webjars/**" ).addResourceLocations ("/webjars/" );
119+ for (String h :applicationProperties .getWebMvc ().getStaticResourceHandler ()){
120+ String location = "classpath:/static" +h +"/" ;
121+ registry .addResourceHandler (h +"/*" ).addResourceLocations (location );
122+ registry .addResourceHandler (h +"/**" ).addResourceLocations (location );
123+ }
124+ for (String h :applicationProperties .getWebMvc ().getDynaicResourceHandler ()){
125+ String location = h +"/" ;
126+ registry .addResourceHandler (h +"/*" ).addResourceLocations (location );
127+ registry .addResourceHandler (h +"/**" ).addResourceLocations (location );
128+ }
87129 }
88130}
0 commit comments