Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

555
Views
El proyecto Spring Boot no puede acceder a archivos estáticos

Creé un nuevo proyecto springboot, la estructura de directorios del proyecto es la siguiente: ingrese la descripción de la imagen aquí La configuración de yml es la siguiente:

 server: port: 8783 servlet: context-path: /spring-demo spring: scan : com.example application: name: spring-demo mvc: view: suffix: .html prefix: / web: resources: static-path-pattern: /** static-locations: classpath:/templates/,classpath:/static/ thymeleaf: cache: false suffix: .html

IndexController es el siguiente

 import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class IndexController { @RequestMapping("/index") public String index(){ System.out.println("index"); return "/index"; } }

índice.html

 <!DOCTYPE html> <html lang=""> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="icon" href="/static/favicon.ico"> <title>private-report</title> </head> <body><noscript><strong>We're sorry but private-report doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript> <div id="app"></div> <link href="/static/js/chunk-vendors.365b8cfb.js" rel="preload" as="script"> </body> </html>

Cuando inicio el servicio de demostración de primavera e ingreso http://localhost:8783/spring-demo/index en el navegador, la página informa un error, ingrese la descripción de la imagen aquí

Se puede acceder a la interfaz de índice, pero no se puede acceder al archivo js y se informa un error 404.

Lo intenté de muchas maneras, pero no pude acceder al archivo js, y la versión de arranque de primavera es 2.5.5 .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

He encontrado tu error. Utiliza la ruta de contexto raíz spring-demo que no se aplica a la ruta relativa según sea necesario

Debes convertirlo en

 <link href="/spring-demo/static/js/chunk-vendors.365b8cfb.js" rel="preload" as="script">
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!