Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

javascript - 404 on handsontable after moving it to resource folder

I am trying to install in spring boot application handsontable locally. After downloading, I moved the handsontable to the resource folder and registered the paths to the css and js files, but the browser keeps returning an error that the file was not found.

handsontable:7 GET http://localhost/src/main/resources/static/handsontableV/dist/handsontable.full.min.js net::ERR_ABORTED 404

My project structure:

enter image description here

My html :

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
      xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <title>Spring Security Example </title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" type="text/css" href="src/main/resources/static/handsontableV/dist/handsontable.full.min.js" media="screen">
    <script src="src/main/resources/static/handsontableV/dist/handsontable.full.min.js"></script>
<!--    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/handsontable.full.min.js"></script>-->
<!--    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/handsontable.full.min.css" rel="stylesheet" media="screen">-->

    <link rel="stylesheet" href="/webjars/bootstrap/4.5.3/css/bootstrap.min.css" />
    <script src="/webjars/bootstrap/4.5.3/js/bootstrap.min.js"></script>
    <script src="/webjars/jquery/3.1.1/jquery.min.js"></script>
</head>

WebConfig :

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("src/main/resources/static/handsontableV/dist/handsontable.full.min.js")
                .addResourceLocations("src/main/resources/static/handsontableV/dist/handsontable.full.min.js");

        registry
                .addResourceHandler("src/main/resources/static/handsontableV/dist/handsontable.full.min.css")
                .addResourceLocations("src/main/resources/static/handsontableV/dist/handsontable.full.min.css");

        registry
                .addResourceHandler("/webjars/**")
                .addResourceLocations("/webjars/");

    }
}

WebSecurityConfig :

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private UserService userService;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Bean
    public PasswordEncoder getPasswordEncoder() {
        return new BCryptPasswordEncoder(8);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
            .authorizeRequests()
            .antMatchers("/login", "/registration","/webjars/**", "/static/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .permitAll();
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web
                .ignoring()
                .antMatchers("/resources/**");
    }

Response from Google Chrome :

enter image description here

I do not understand. I tried changing the path to static / handsontableV / dist / handsontable.full.min.js

but it doesn't work. For what reason may spring not see the file?

question from:https://stackoverflow.com/questions/65842015/404-on-handsontable-after-moving-it-to-resource-folder

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I decided to create a webapp folder

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...