【问题标题】:Why application.properties is not executing properties after applying spring security in spring boot application?为什么在 Spring Boot 应用程序中应用 Spring Security 后 application.properties 不执行属性?
【发布时间】:2018-09-25 03:51:58
【问题描述】:

我创建了一个 spring-boot 应用程序。它工作正常,所有 cssjs 都与我的 jsp 页面完美映射,并且应用程序能够映射到我的 jsp 页也是如此。通过资源文件夹中的 appication.properties 文件。

spring.mvc.view.prefix = /WEB-INF/views/
spring.mvc.view.suffix = .jsp
spring.mvc.static-path-pattern=/resources/**
server.port=8181

但由于我启用了 Spring 安全性,我无法做到这一点,我需要初始化 @bean 类

@Bean
  public ViewResolver viewResolver() {
      InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
      viewResolver.setPrefix("/WEB-INF/views/");
      viewResolver.setSuffix(".jsp");
      return viewResolver;
  }

这很奇怪。有人可以帮我吗?

提前谢谢你,

普里亚尔沙阿。

【问题讨论】:

  • 任何错误或异常?
  • @Alien 如果我不应用 Bean,它会给我 500 错误 Servlet.service() for servlet [dispatcherServlet] 在路径 [] 的上下文中抛出异常 [无法解析名称为“登录”的视图在名称为'dispatcherServlet']的servlet中,根本原因
  • 您是如何启用安全性的...您不需要为此做任何事情。

标签: spring spring-mvc spring-boot spring-security application.properties


【解决方案1】:

确保您的类正在扩展 WebMvcConfigurerAdapter 类,如下例所示。

@Configuration
@ComponentScan(basePackages="com.package")
@EnableWebMvc
public class MvcConfigs extends WebMvcConfigurerAdapter{

    @Bean
    public ViewResolver getViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}

【讨论】:

  • 我已经这样做了。@Alien 我需要一个答案,为什么 application.properties 不起作用?
  • 而且我也无法访问 src/main/resources/static/* 中的 css 和 js 文件,我使用了 spring.mvc.static-path-pattern=/resources/**在 application.properties 中,没有它我如何使它工作?@Alien
  • 你无法访问 css 因为@EnableWebMvc 注解会禁用 Spring Boot 对 Spring MVC 的自动配置。
  • 好的,那么我如何访问该 css?我尝试删除 @EnableWebMvc 它没有用。 @外星人
猜你喜欢
  • 2023-02-10
  • 2017-06-17
  • 1970-01-01
  • 2016-12-18
  • 2019-07-25
  • 1970-01-01
  • 2019-12-26
  • 2017-06-17
  • 2016-07-16
相关资源
最近更新 更多