|
1 | | -package com.baeldung.tiles.springmvc; |
2 | | - |
3 | | -import org.springframework.context.annotation.Bean; |
4 | | -import org.springframework.context.annotation.ComponentScan; |
5 | | -import org.springframework.context.annotation.Configuration; |
6 | | -import org.springframework.web.servlet.config.annotation.EnableWebMvc; |
7 | | -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
8 | | -import org.springframework.web.servlet.config.annotation.ViewResolverRegistry; |
9 | | -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
10 | | -import org.springframework.web.servlet.view.tiles3.TilesConfigurer; |
11 | | -import org.springframework.web.servlet.view.tiles3.TilesViewResolver; |
12 | | - |
13 | | -@Configuration |
14 | | -@EnableWebMvc |
15 | | -@ComponentScan(basePackages = "com.baeldung.tiles.springmvc") |
16 | | -public class ApplicationConfiguration extends WebMvcConfigurerAdapter { |
17 | | - |
18 | | - /** |
19 | | - * Configure TilesConfigurer. |
20 | | - */ |
21 | | - @Bean |
22 | | - public TilesConfigurer tilesConfigurer() { |
23 | | - TilesConfigurer tilesConfigurer = new TilesConfigurer(); |
24 | | - tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" }); |
25 | | - tilesConfigurer.setCheckRefresh(true); |
26 | | - return tilesConfigurer; |
27 | | - } |
28 | | - |
29 | | - /** |
30 | | - * Configure ViewResolvers to deliver views. |
31 | | - */ |
32 | | - @Override |
33 | | - public void configureViewResolvers(ViewResolverRegistry registry) { |
34 | | - TilesViewResolver viewResolver = new TilesViewResolver(); |
35 | | - registry.viewResolver(viewResolver); |
36 | | - } |
37 | | - |
38 | | - /** |
39 | | - * Configure ResourceHandlers to serve static resources |
40 | | - */ |
41 | | - |
42 | | - @Override |
43 | | - public void addResourceHandlers(ResourceHandlerRegistry registry) { |
44 | | - registry.addResourceHandler("/static/**").addResourceLocations("/static/"); |
45 | | - } |
46 | | - |
47 | | -} |
| 1 | +package com.baeldung.spring.configuration; |
| 2 | + |
| 3 | +import org.springframework.context.annotation.Bean; |
| 4 | +import org.springframework.context.annotation.ComponentScan; |
| 5 | +import org.springframework.context.annotation.Configuration; |
| 6 | +import org.springframework.web.servlet.config.annotation.EnableWebMvc; |
| 7 | +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
| 8 | +import org.springframework.web.servlet.config.annotation.ViewResolverRegistry; |
| 9 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 10 | +import org.springframework.web.servlet.view.tiles3.TilesConfigurer; |
| 11 | +import org.springframework.web.servlet.view.tiles3.TilesViewResolver; |
| 12 | + |
| 13 | +@Configuration |
| 14 | +@EnableWebMvc |
| 15 | +@ComponentScan(basePackages = "com.baeldung.spring.controller.tiles") |
| 16 | +public class TilesApplicationConfiguration implements WebMvcConfigurer { |
| 17 | + |
| 18 | + /** |
| 19 | + * Configure TilesConfigurer. |
| 20 | + */ |
| 21 | + @Bean |
| 22 | + public TilesConfigurer tilesConfigurer() { |
| 23 | + TilesConfigurer tilesConfigurer = new TilesConfigurer(); |
| 24 | + tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" }); |
| 25 | + tilesConfigurer.setCheckRefresh(true); |
| 26 | + return tilesConfigurer; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Configure ViewResolvers to deliver views. |
| 31 | + */ |
| 32 | + @Override |
| 33 | + public void configureViewResolvers(ViewResolverRegistry registry) { |
| 34 | + TilesViewResolver viewResolver = new TilesViewResolver(); |
| 35 | + registry.viewResolver(viewResolver); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Configure ResourceHandlers to serve static resources |
| 40 | + */ |
| 41 | + |
| 42 | + @Override |
| 43 | + public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| 44 | + registry.addResourceHandler("/static/**").addResourceLocations("/static/"); |
| 45 | + } |
| 46 | + |
| 47 | +} |
0 commit comments