1
1
package org .woehlke .simpleworklist .config .di ;
2
2
3
+ import org .springframework .beans .factory .annotation .Autowired ;
3
4
import org .springframework .boot .autoconfigure .ImportAutoConfiguration ;
4
5
import org .springframework .boot .context .properties .EnableConfigurationProperties ;
5
6
import org .springframework .context .MessageSource ;
6
7
import org .springframework .context .annotation .Bean ;
7
8
import org .springframework .context .annotation .Configuration ;
8
9
import org .springframework .context .support .ResourceBundleMessageSource ;
9
10
import org .springframework .data .jpa .repository .config .EnableJpaAuditing ;
11
+ import org .springframework .data .jpa .repository .config .EnableJpaRepositories ;
10
12
import org .springframework .data .web .config .EnableSpringDataWebSupport ;
13
+ import org .springframework .mail .javamail .JavaMailSender ;
14
+ import org .springframework .mail .javamail .JavaMailSenderImpl ;
11
15
import org .springframework .scheduling .annotation .EnableAsync ;
12
16
import org .springframework .session .jdbc .config .annotation .web .http .EnableJdbcHttpSession ;
13
17
import org .springframework .validation .beanvalidation .MethodValidationPostProcessor ;
19
23
import org .woehlke .simpleworklist .config .ApplicationProperties ;
20
24
21
25
import java .util .Locale ;
26
+ import java .util .Properties ;
22
27
23
28
24
29
@ Configuration
27
32
@ EnableWebMvc
28
33
@ EnableSpringDataWebSupport
29
34
@ EnableJdbcHttpSession
30
- @ ImportAutoConfiguration ({
31
- ApplicationConfig . class
35
+ @ EnableJpaRepositories ({
36
+ "org.woehlke.simpleworklist"
32
37
})
33
38
@ EnableConfigurationProperties ({
34
39
ApplicationProperties .class
35
40
})
36
41
public class WebMvcConfig extends WebMvcConfigurerAdapter implements WebMvcConfigurer {
37
42
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
+
38
78
@ Bean
39
79
public LocaleResolver localeResolver () {
40
80
SessionLocaleResolver slr = new SessionLocaleResolver ();
@@ -51,9 +91,9 @@ public LocaleChangeInterceptor localeChangeInterceptor() {
51
91
52
92
@ Bean
53
93
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 ;
57
97
}
58
98
59
99
@ Bean
@@ -76,13 +116,15 @@ public void addViewControllers(ViewControllerRegistry registry) {
76
116
}
77
117
78
118
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
+ }
87
129
}
88
130
}
0 commit comments