View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.shiro.samples.spring.config;
20  
21  import org.springframework.context.annotation.Bean;
22  import org.springframework.context.annotation.ComponentScan;
23  import org.springframework.context.annotation.Configuration;
24  import org.springframework.core.annotation.Order;
25  import org.springframework.web.servlet.ViewResolver;
26  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
27  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
28  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
29  import org.springframework.web.servlet.view.InternalResourceViewResolver;
30  import org.springframework.web.servlet.view.JstlView;
31  
32  /**
33   * JSP / HTML views and resource bean definitions.
34   */
35  @Configuration
36  @ComponentScan("org.apache.shiro.samples.spring")
37  @EnableWebMvc
38  public class JspViewsConfig extends WebMvcConfigurerAdapter {
39  
40      @Bean
41      @Order(1)
42      public ViewResolver getViewResolver(){
43          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
44          resolver.setViewClass(JstlView.class);
45          resolver.setPrefix("/WEB-INF/resources/");
46          resolver.setSuffix(".jsp");
47          return resolver;
48      }
49  
50      @Bean
51      @Order(0)
52      public ViewResolver jnlpViewResolver() {
53          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
54          resolver.setViewClass(JstlView.class);
55          resolver.setPrefix("/WEB-INF/jnlp/");
56          resolver.setSuffix(".jsp");
57          return resolver;
58      }
59  
60      @Override
61      public void addResourceHandlers(ResourceHandlerRegistry registry) {
62          registry.addResourceHandler("*.css", "*.png").addResourceLocations("/");
63          registry.addResourceHandler("*.jar", "*.pack").addResourceLocations("/WEB-INF/resources/");
64      }
65  }