실습환경
개발환경
windows10(64)
spring4
java1.8
tomcat9
들어가기 lagacy HTML5셋팅이란 Thymeleaf는 Well-Formed XML로 HTML을 작성해야 한다. 즉 XHTML 문법처럼 모든 태그를 닫아주어야 한다. 따라서 HTML5로 작성된 디자인, 예를 들어 아래와 같이 br태그를 닫아주지 않는다면 서버 실행시 오류를 발생하며 동작하지 않게 된다. tomcat 자체가 아예 동작하지 않는 것은 좀 충격적이었다….
lagacy HTML5셋팅은 Thymeleaf를 Well-Formed XML로 html을 작성하는 것이 아니라 HTML5 문법으로 작성할수 있게 도와주는 셋팅이다.
thymeleaf lagacy html5 셋팅 1.pom.xml 설정
혹시나해서 thymeleaf 관련 전체 내용보여주겠다. nekohtml 가 lagacy html5관련 라이브러릴다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 <dependency > <groupId > org.thymeleaf</groupId > <artifactId > thymeleaf</artifactId > <version > 3.0.9.RELEASE</version > </dependency > <dependency > <groupId > org.thymeleaf</groupId > <artifactId > thymeleaf-spring4</artifactId > <version > 3.0.9.RELEASE</version > </dependency > <dependency > <groupId > nz.net.ultraq.thymeleaf</groupId > <artifactId > thymeleaf-layout-dialect</artifactId > <version > 2.3.0</version > </dependency > <dependency > <groupId > net.sourceforge.nekohtml</groupId > <artifactId > nekohtml</artifactId > <version > 1.9.22</version > </dependency >
2.servlet-context.xml 설정
음 아래 내용은 관련이 있는지 없는지 정확히 모르겠다. 하지만 혹시나 해서 기록한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 <beans:bean id ="templateResolver" class ="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver" > <beans:property name ="prefix" value ="/WEB-INF/views/" /> <beans:property name ="suffix" value =".html" /> <beans:property name ="templateMode" value ="HTML" /> <beans:property name ="characterEncoding" value ="UTF-8" /> <beans:property name ="cacheable" value ="false" /> </beans:bean > <beans:bean id ="templateEngine" class ="org.thymeleaf.spring4.SpringTemplateEngine" > <beans:property name ="templateResolver" ref ="templateResolver" /> <beans:property name ="additionalDialects" > <beans:set > <beans:bean class ="nz.net.ultraq.thymeleaf.LayoutDialect" /> </beans:set > </beans:property > </beans:bean > <beans:bean class ="org.thymeleaf.spring4.view.ThymeleafViewResolver" > <beans:property name ="templateEngine" ref ="templateEngine" /> <beans:property name ="characterEncoding" value ="UTF-8" /> <beans:property name ="order" value ="1" /> </beans:bean >
3.application.properties 파일 생성하기.
src/main/resources 폴더에 application.properties 파일을 생성하고 내용을 아래처럼 채우자.
1 spring.thymeleaf.mode=LEGACYHTML5
4.thymeleaf에서 html5 문법 동작확인 즉 br태그를 html5형식으로 닫지않고 사용했을때 서버가 동작하는지 확인해보자.
Related Posts “spring4 thymeleaf2 버전 설정” “spring4 thymeleaf3 버전 설정”