无法使用 Thymeleaf 加载静态资源

发布于 2025-01-15 04:56:30 字数 13436 浏览 1 评论 0原文

在我的多模块 Spring Boot 项目中,我已将 thymeleaf 包含在 bo_ui 模块中以显示 html 页面。

以下是迄今为止已完成的工作。

MVC 配置类:

@Configuration
@EnableWebMvc
@ComponentScan({ "com.cmw.bo.console" })
/**
 * Java configuration file that is used for Spring MVC and Thymeleaf
 * configurations
 */
public class WebMVCConfig implements WebMvcConfigurer,  ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.addPathPrefix("/ui", HandlerTypePredicate.forBasePackage("com.cmw.ui"))
//                  .addPathPrefix("/basis", HandlerTypePredicate.forBasePackage("com.cmw.basis"))
                  .addPathPrefix("/api", HandlerTypePredicate.forBasePackage("com.cmw.api"));
    }

    @Bean
    public ViewResolver htmlViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine(htmlTemplateResolver()));
        resolver.setContentType("text/html");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setViewNames(ArrayUtil.array("*.html"));
        return resolver;
    }

    @Bean
    public ViewResolver javascriptViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine(javascriptTemplateResolver()));
        resolver.setContentType("application/javascript");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setViewNames(ArrayUtil.array("*.js"));
        return resolver;
    }

    @Bean
    public ViewResolver plainViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine(plainTemplateResolver()));
        resolver.setContentType("text/plain");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setViewNames(ArrayUtil.array("*.txt"));
        return resolver;
    }

    private ISpringTemplateEngine templateEngine(ITemplateResolver templateResolver) {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.addDialect(new LayoutDialect(new GroupingStrategy()));
        engine.addDialect(new Java8TimeDialect());
        engine.setTemplateResolver(templateResolver);
        engine.setTemplateEngineMessageSource(messageSource());
        return engine;
    }

    @Bean
    public ITemplateResolver htmlTemplateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("classpath:/templates/");
        resolver.setCacheable(false);
        resolver.setOrder(0);
        resolver.setTemplateMode(TemplateMode.HTML);
        return resolver;
    }

    private ITemplateResolver javascriptTemplateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("classpath:/public/js/");
        resolver.setOrder(1);
        resolver.setCacheable(false);
        resolver.setTemplateMode(TemplateMode.JAVASCRIPT);
        return resolver;
    }

    private ITemplateResolver plainTemplateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("classpath:/templates/txt/");
        resolver.setCacheable(false);
        resolver.setTemplateMode(TemplateMode.TEXT);
        return resolver;
    }

    @Bean
    @Description("Spring Message Resolver")
    public ResourceBundleMessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename("messages");
        return messageSource;
    }

    @Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver localeResolver = new SessionLocaleResolver();
        localeResolver.setDefaultLocale(new Locale("it"));
        return localeResolver;
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("lang");
        return localeChangeInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }

    @Override
    @Description("Custom Conversion Service")
    public void addFormatters(FormatterRegistry registry) {
        registry.addFormatter(new NameFormatter());
    }
    
}

Thymeleaf 依赖项:

<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf</artifactId>
    <version>3.0.11.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf-spring5</artifactId>
    <version>3.0.11.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-java8time</artifactId>
    <version>3.0.4.RELEASE</version>
</dependency>

<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
    <version>3.0.0</version>
</dependency>

testPage.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>my test</title>
    <script th:src="@{/public/js/test.js}"></script>
</head>
<body>
<h2>this is a test page</h2>
</body>
</html>

项目资源文件夹:

在此处输入图像描述

当我尝试通过端点访问 testPage.html 时,页面加载正确,但检查元素时我看到test.js 上出现 404 错误。

我尝试了 public 文件夹和 static 文件夹。

查看 springboot 日志,我看到:

2022-03-18 16:10:27.372 DEBUG 8940 --- [nio-8080-exec-3] o.s.security.web.FilterChainProxy        : Secured GET /public/js/test.js
2022-03-18 16:10:27.375  WARN 8940 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound             : No mapping for GET /public/js/test.js

所以我认为 springsecurity 级别也存在问题。这是配置:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    private static final String REMEMBER_ME_INTERNAL_SHARED_KEY = "f1406c2dfghdfghf-26e3-dfgh45ed-8dfgh19c-dfgh4131cadaa431";

    private static final String REMEMBER_ME_COOKIE_NAME = "cmw-session-id";
    private static final String SESSION_COOKIE_NAME = "JSESSIONID";

    @Autowired
    private OperatorsAuthenticationService authenticationService;

    @Autowired
    @Qualifier("basisDataSource")
    private DataSource dataSource;


    @Bean
    public static RoleHierarchyImpl roleHierarchy() {

        RoleHierarchyImpl hierarchy = new RoleHierarchyImpl();
        hierarchy.setHierarchy(

                "ROLE_ADMIN > ROLE_MANAGER\n" +
                        "ROLE_MANAGER > ROLE_HELPDESK\n" +
                        "ROLE_HELPDESK > ROLE_MARKETING\n" +
                        "ROLE_MARKETING > ROLE_OPERATOR\n" +
                        "ROLE_OPERATOR > ROLE_USER"
        );

        return hierarchy;
    }



    @Override
    public void configure(WebSecurity web) throws Exception {

        web
                .ignoring()
                .antMatchers("/resources/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
                .authorizeRequests()
                .antMatchers("/resources**").permitAll()
                .antMatchers("/static**").permitAll()
                .antMatchers("/public**").permitAll()
                .antMatchers("/login**").permitAll()
                .antMatchers("/basis/otp/**").permitAll()
                .antMatchers("/basis/customers/1").permitAll()
                .antMatchers("/basis/customers/3").permitAll()
                .antMatchers("/basis/profiles/**/chpass/otp/**").permitAll()
                .antMatchers("/basis/operators/chpass/**").permitAll()
                .antMatchers("/admin**").hasRole("ADMIN")
                .anyRequest().hasAnyRole("ADMIN", "MANAGER", "HELPDESK", "MARKETING", "OPERATOR")
//                .anyRequest().authenticated()
                .accessDecisionManager(accessDecisionManager())
                .and()
                .formLogin().loginPage("/login").permitAll()
                .failureHandler(authenticationFailureHandler())
                .and()
                .httpBasic()
                .and()
                .rememberMe()
                .rememberMeServices(rememberMeServices())
                .key(REMEMBER_ME_INTERNAL_SHARED_KEY)
                .and()
                .logout()
                .logoutUrl("/logout")
                .logoutSuccessUrl("/login")
                .invalidateHttpSession(true)
                .deleteCookies(REMEMBER_ME_COOKIE_NAME, SESSION_COOKIE_NAME)
                .and()
                .sessionManagement()
                .invalidSessionUrl("/login");
    }

    @Bean
    public AuthenticationProvider authenticationProvider() {

        return new AuthenticationProviderImpl();
    }

//    @Bean
//    public AuthenticationProvider googleAuthenticationProvider() {
//
//        return new GoogleAuthenticationProviderImpl();
//    }

    @Bean
    public RememberMeServices rememberMeServices() {

        PersistentTokenBasedRememberMeServices services = new PersistentTokenBasedRememberMeServices(REMEMBER_ME_INTERNAL_SHARED_KEY,
                authenticationService, tokenRepository());
        services.setAlwaysRemember(true);
        services.setTokenValiditySeconds(432000);
        services.setCookieName(REMEMBER_ME_COOKIE_NAME);
        services.setParameter("remember-me");

        return services;
    }

    @Bean
    public PersistentTokenRepository tokenRepository() {

        JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
        tokenRepository.setDataSource(dataSource);
        tokenRepository.setCreateTableOnStartup(false); // Set to false in production

        return tokenRepository;
    }

    @Bean
    public DefaultWebSecurityExpressionHandler webSecurityExpressionHandler() {

        DefaultWebSecurityExpressionHandler expressionHandler = new DefaultWebSecurityExpressionHandler();
        expressionHandler.setRoleHierarchy(roleHierarchy());

        return expressionHandler;
    }

    @Bean
    public WebExpressionVoter webExpressionVoter() {

        WebExpressionVoter webExpressionVoter = new WebExpressionVoter();
        webExpressionVoter.setExpressionHandler(webSecurityExpressionHandler());

        return webExpressionVoter;
    }

    @Bean
    public RoleHierarchyVoter roleHierarchyVoter() {

        return new RoleHierarchyVoter(roleHierarchy());
    }

    @Bean
    @SuppressWarnings("unchecked")
    public AffirmativeBased accessDecisionManager() {

        List<AccessDecisionVoter<?>> voters = new ArrayList<>();
        voters.add(roleHierarchyVoter());
        voters.add(webExpressionVoter());

        return new AffirmativeBased(voters);
    }

    @Bean
    protected AuthenticationFailureHandler authenticationFailureHandler() {

        Map<String, String> exceptionMappings = new HashMap<>();

        exceptionMappings.put(InternalAuthenticationServiceException.class.getCanonicalName(), "/login?error=serverError");
        exceptionMappings.put(AuthenticationServiceException.class.getCanonicalName(), "/login?error=serverError");
        exceptionMappings.put(BadCredentialsException.class.getCanonicalName(), "/login?error=authfailed");
        exceptionMappings.put(DisabledException.class.getCanonicalName(), "/login?error=disabled");
        exceptionMappings.put(UsernameNotFoundException.class.getCanonicalName(), "/login?error=usernameNotFound");
        exceptionMappings.put(CredentialsExpiredException.class.getCanonicalName(), "/login?error=usernameNotFound");
        exceptionMappings.put(AuthenticationCredentialsNotFoundException.class.getCanonicalName(), "/login?error=usernameNotFound");

        exceptionMappings.put(UsernameCredentialsExpiredException.class.getCanonicalName(), "/basis/operators/chpass");

        final UsernameCachingExceptionMappingAuthenticationFailureHandler result = new UsernameCachingExceptionMappingAuthenticationFailureHandler();
        result.setExceptionMappings(exceptionMappings);
        result.setDefaultFailureUrl("/login?error=default");

        return result;
    }

}

我尝试了几种配置但没有成功。

任何人都知道可能出了什么问题吗?

提前致谢

In my multi-module spring boot project I have included thymeleaf in the bo_ui module to show html pages.

Below what has been done so far.

MVC configuration class:

@Configuration
@EnableWebMvc
@ComponentScan({ "com.cmw.bo.console" })
/**
 * Java configuration file that is used for Spring MVC and Thymeleaf
 * configurations
 */
public class WebMVCConfig implements WebMvcConfigurer,  ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.addPathPrefix("/ui", HandlerTypePredicate.forBasePackage("com.cmw.ui"))
//                  .addPathPrefix("/basis", HandlerTypePredicate.forBasePackage("com.cmw.basis"))
                  .addPathPrefix("/api", HandlerTypePredicate.forBasePackage("com.cmw.api"));
    }

    @Bean
    public ViewResolver htmlViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine(htmlTemplateResolver()));
        resolver.setContentType("text/html");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setViewNames(ArrayUtil.array("*.html"));
        return resolver;
    }

    @Bean
    public ViewResolver javascriptViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine(javascriptTemplateResolver()));
        resolver.setContentType("application/javascript");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setViewNames(ArrayUtil.array("*.js"));
        return resolver;
    }

    @Bean
    public ViewResolver plainViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine(plainTemplateResolver()));
        resolver.setContentType("text/plain");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setViewNames(ArrayUtil.array("*.txt"));
        return resolver;
    }

    private ISpringTemplateEngine templateEngine(ITemplateResolver templateResolver) {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.addDialect(new LayoutDialect(new GroupingStrategy()));
        engine.addDialect(new Java8TimeDialect());
        engine.setTemplateResolver(templateResolver);
        engine.setTemplateEngineMessageSource(messageSource());
        return engine;
    }

    @Bean
    public ITemplateResolver htmlTemplateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("classpath:/templates/");
        resolver.setCacheable(false);
        resolver.setOrder(0);
        resolver.setTemplateMode(TemplateMode.HTML);
        return resolver;
    }

    private ITemplateResolver javascriptTemplateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("classpath:/public/js/");
        resolver.setOrder(1);
        resolver.setCacheable(false);
        resolver.setTemplateMode(TemplateMode.JAVASCRIPT);
        return resolver;
    }

    private ITemplateResolver plainTemplateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("classpath:/templates/txt/");
        resolver.setCacheable(false);
        resolver.setTemplateMode(TemplateMode.TEXT);
        return resolver;
    }

    @Bean
    @Description("Spring Message Resolver")
    public ResourceBundleMessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename("messages");
        return messageSource;
    }

    @Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver localeResolver = new SessionLocaleResolver();
        localeResolver.setDefaultLocale(new Locale("it"));
        return localeResolver;
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("lang");
        return localeChangeInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }

    @Override
    @Description("Custom Conversion Service")
    public void addFormatters(FormatterRegistry registry) {
        registry.addFormatter(new NameFormatter());
    }
    
}

Thymeleaf dependencies:

<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf</artifactId>
    <version>3.0.11.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf-spring5</artifactId>
    <version>3.0.11.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-java8time</artifactId>
    <version>3.0.4.RELEASE</version>
</dependency>

<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
    <version>3.0.0</version>
</dependency>

testPage.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>my test</title>
    <script th:src="@{/public/js/test.js}"></script>
</head>
<body>
<h2>this is a test page</h2>
</body>
</html>

resources folder of the project:

enter image description here

When I try to reach the testPage.html through my endpoint, the page loads correctly, but inspecting the elements I see a 404 error on test.js.

I tried on both the public folder and the static folder.

Looking at the springboot logs I see:

2022-03-18 16:10:27.372 DEBUG 8940 --- [nio-8080-exec-3] o.s.security.web.FilterChainProxy        : Secured GET /public/js/test.js
2022-03-18 16:10:27.375  WARN 8940 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound             : No mapping for GET /public/js/test.js

So I suppose there is also a problem at the springsecurity level. Here is the configuration:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    private static final String REMEMBER_ME_INTERNAL_SHARED_KEY = "f1406c2dfghdfghf-26e3-dfgh45ed-8dfgh19c-dfgh4131cadaa431";

    private static final String REMEMBER_ME_COOKIE_NAME = "cmw-session-id";
    private static final String SESSION_COOKIE_NAME = "JSESSIONID";

    @Autowired
    private OperatorsAuthenticationService authenticationService;

    @Autowired
    @Qualifier("basisDataSource")
    private DataSource dataSource;


    @Bean
    public static RoleHierarchyImpl roleHierarchy() {

        RoleHierarchyImpl hierarchy = new RoleHierarchyImpl();
        hierarchy.setHierarchy(

                "ROLE_ADMIN > ROLE_MANAGER\n" +
                        "ROLE_MANAGER > ROLE_HELPDESK\n" +
                        "ROLE_HELPDESK > ROLE_MARKETING\n" +
                        "ROLE_MARKETING > ROLE_OPERATOR\n" +
                        "ROLE_OPERATOR > ROLE_USER"
        );

        return hierarchy;
    }



    @Override
    public void configure(WebSecurity web) throws Exception {

        web
                .ignoring()
                .antMatchers("/resources/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
                .authorizeRequests()
                .antMatchers("/resources**").permitAll()
                .antMatchers("/static**").permitAll()
                .antMatchers("/public**").permitAll()
                .antMatchers("/login**").permitAll()
                .antMatchers("/basis/otp/**").permitAll()
                .antMatchers("/basis/customers/1").permitAll()
                .antMatchers("/basis/customers/3").permitAll()
                .antMatchers("/basis/profiles/**/chpass/otp/**").permitAll()
                .antMatchers("/basis/operators/chpass/**").permitAll()
                .antMatchers("/admin**").hasRole("ADMIN")
                .anyRequest().hasAnyRole("ADMIN", "MANAGER", "HELPDESK", "MARKETING", "OPERATOR")
//                .anyRequest().authenticated()
                .accessDecisionManager(accessDecisionManager())
                .and()
                .formLogin().loginPage("/login").permitAll()
                .failureHandler(authenticationFailureHandler())
                .and()
                .httpBasic()
                .and()
                .rememberMe()
                .rememberMeServices(rememberMeServices())
                .key(REMEMBER_ME_INTERNAL_SHARED_KEY)
                .and()
                .logout()
                .logoutUrl("/logout")
                .logoutSuccessUrl("/login")
                .invalidateHttpSession(true)
                .deleteCookies(REMEMBER_ME_COOKIE_NAME, SESSION_COOKIE_NAME)
                .and()
                .sessionManagement()
                .invalidSessionUrl("/login");
    }

    @Bean
    public AuthenticationProvider authenticationProvider() {

        return new AuthenticationProviderImpl();
    }

//    @Bean
//    public AuthenticationProvider googleAuthenticationProvider() {
//
//        return new GoogleAuthenticationProviderImpl();
//    }

    @Bean
    public RememberMeServices rememberMeServices() {

        PersistentTokenBasedRememberMeServices services = new PersistentTokenBasedRememberMeServices(REMEMBER_ME_INTERNAL_SHARED_KEY,
                authenticationService, tokenRepository());
        services.setAlwaysRemember(true);
        services.setTokenValiditySeconds(432000);
        services.setCookieName(REMEMBER_ME_COOKIE_NAME);
        services.setParameter("remember-me");

        return services;
    }

    @Bean
    public PersistentTokenRepository tokenRepository() {

        JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
        tokenRepository.setDataSource(dataSource);
        tokenRepository.setCreateTableOnStartup(false); // Set to false in production

        return tokenRepository;
    }

    @Bean
    public DefaultWebSecurityExpressionHandler webSecurityExpressionHandler() {

        DefaultWebSecurityExpressionHandler expressionHandler = new DefaultWebSecurityExpressionHandler();
        expressionHandler.setRoleHierarchy(roleHierarchy());

        return expressionHandler;
    }

    @Bean
    public WebExpressionVoter webExpressionVoter() {

        WebExpressionVoter webExpressionVoter = new WebExpressionVoter();
        webExpressionVoter.setExpressionHandler(webSecurityExpressionHandler());

        return webExpressionVoter;
    }

    @Bean
    public RoleHierarchyVoter roleHierarchyVoter() {

        return new RoleHierarchyVoter(roleHierarchy());
    }

    @Bean
    @SuppressWarnings("unchecked")
    public AffirmativeBased accessDecisionManager() {

        List<AccessDecisionVoter<?>> voters = new ArrayList<>();
        voters.add(roleHierarchyVoter());
        voters.add(webExpressionVoter());

        return new AffirmativeBased(voters);
    }

    @Bean
    protected AuthenticationFailureHandler authenticationFailureHandler() {

        Map<String, String> exceptionMappings = new HashMap<>();

        exceptionMappings.put(InternalAuthenticationServiceException.class.getCanonicalName(), "/login?error=serverError");
        exceptionMappings.put(AuthenticationServiceException.class.getCanonicalName(), "/login?error=serverError");
        exceptionMappings.put(BadCredentialsException.class.getCanonicalName(), "/login?error=authfailed");
        exceptionMappings.put(DisabledException.class.getCanonicalName(), "/login?error=disabled");
        exceptionMappings.put(UsernameNotFoundException.class.getCanonicalName(), "/login?error=usernameNotFound");
        exceptionMappings.put(CredentialsExpiredException.class.getCanonicalName(), "/login?error=usernameNotFound");
        exceptionMappings.put(AuthenticationCredentialsNotFoundException.class.getCanonicalName(), "/login?error=usernameNotFound");

        exceptionMappings.put(UsernameCredentialsExpiredException.class.getCanonicalName(), "/basis/operators/chpass");

        final UsernameCachingExceptionMappingAuthenticationFailureHandler result = new UsernameCachingExceptionMappingAuthenticationFailureHandler();
        result.setExceptionMappings(exceptionMappings);
        result.setDefaultFailureUrl("/login?error=default");

        return result;
    }

}

I have tried several configurations but without success.

Anyone have an idea what could be wrong?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅渡 2025-01-22 04:56:30

检查您的 public.js 目录名称。您想要访问 public/js/test.js 但不存在!我不确定这是一个主要问题,但它可以提供帮助。

Check your public.js directory name. You want to reach public/js/test.js and is not exist! I am not sure that is a main problem but it can help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文