JQuery를 스프링 부트 프로젝트 (Spring to New)에 통합하는 데 문제가 있습니다. 나는 문서를 따라하려고했지만 여전히 작동하지 않습니다. Java/Spring + Thymeleaf를 사용하고 있습니다. ,스프링 부트에서 JQuery 통합
- WebJar는
- WebJar 응용 프로그램의 실행 CLASSPATH
- 컨테이너, 웹 프레임 워크에 있어야 응용 프로그램의 종속성 할 필요가 : 문서는 다음 작업을 수행 할 필요가 있다고 또는 응용 프로그램이 Jar 파일에서 고정 자산을 제공 할 필요가
참조 : http://www.webjars.org/documentation#springboot
,536 WebMvcConfigurerAdapter 클래스를 확장 내 구성 클래스에<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-securing-web</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- tag::security[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- end::security[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
그리고 나는 또한 추가 리소스 핸들러 :
여기 내 pom.xml 파일입니다.
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
그런 다음 내 HTML 파일에 내가 다음 줄이 있습니다 :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Hello World!</title>
<script type="text/javascript">
jQuery(document).ready(function($) {
alert("JQuery works");
});
</script>
</head>
<body>
<h1 th:inline="text">Hello [[${#httpServletRequest.remoteUser}]]!</h1>
<form th:action="@{/logout}" method="post">
<input type="submit" value="Sign Out"/>
</form>
<script type="text/javascript" src="webjars/jquery/3.2.0/jquery.min.js"></script>
</body>
</html>
을하지만 JQuery와 아직로드되지 않은 나는 다음과 같은 방법을 추가했습니다. 그것은 정의되지 않았다고 말합니다. 누군가가 무엇이 잘못되었는지 말해 줄 수 있습니까?
오케이. 이 기사는 http://idiallo.com/javascript/async-jquery에 있습니다. 그것은 타이밍을 가지고 뭔가를해야만하는 것처럼 보입니다. 더 깊게 파고 갈거야. 그러나 어쨌든, 나는 나의 문제를 해결했다. 경우 폐쇄. – user4080732
'jQuery'를 사용하기 전에 jQuery를로드해야합니다. –