2016-11-30 6 views
2

sendind 이메일 용 스프링 부팅 응용 프로그램을 개발하려고합니다. 모두 괜찮습니다.하지만 템플리트 템플릿에서 이미지를 추가하려고하면 오류가 표시됩니다.봄 부팅 thymeleaf 이미지

ERROR [[/jira-rct/v1.0].[dispatcherServlet]] [http-nio-8080-exec-1] Servlet.service() for servlet [dispatcherServlet] in context with path [/jira-rct/v1.0] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Link base "/img/crm-signature.png" cannot be context relative (/) or page relative unless you implement the org.thymeleaf.context.IWebContext interface (context is of class: org.thymeleaf.context.Context) (email/template-1:20)] with root cause 
org.thymeleaf.exceptions.TemplateProcessingException: Link base "/img/crm-signature.png" cannot be context relative (/) or page relative unless you implement the org.thymeleaf.context.IWebContext interface (context is of class: org.thymeleaf.context.Context) (email/template-1:20) 
    at org.thymeleaf.standard.expression.LinkExpression.executeLink(LinkExpression.java:270) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:77) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.standard.expression.Expression.execute(Expression.java:103) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.standard.expression.Expression.execute(Expression.java:133) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.standard.expression.Expression.execute(Expression.java:120) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.standard.processor.attr.AbstractStandardSingleAttributeModifierAttrProcessor.getTargetAttributeValue(AbstractStandardSingleAttributeModifierAttrProcessor.java:67) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.spring4.processor.attr.SpringSrcAttrProcessor.getTargetAttributeValue(SpringSrcAttrProcessor.java:68) ~[thymeleaf-spring4-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.processor.attr.AbstractSingleAttributeModifierAttrProcessor.getModifiedAttributeValues(AbstractSingleAttributeModifierAttrProcessor.java:59) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor.processAttribute(AbstractAttributeModifierAttrProcessor.java:62) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:1017) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.Node.processNode(Node.java:972) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
    at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 

안부

+0

당신이 "SRC/메인/자원/공개"내부의 img 폴더를해야합니까? – cralfaro

+0

또한 img/crm-signature.png는 img/signature.png와 다릅니다 – cralfaro

답변

1

구문이 옳다 : 이 내 template.html

<!DOCTYPE html> 
<html xmlns:th="http://www.thymeleaf.org"> 
<head> 
    <title th:remove="all">Order Confirmation</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
</head> 
<body> 
<div> 

    <h2 th:text="${title}">title</h2> 
    <p th:utext="${description}"> 
      description 
    </p> 

    <br /> 
    <br /> 
    <br /> 
    <p>Bien cordialement</p> 
    <div> 
     <img th:src="@{/img/signature.png}" /> 

    </div> 
</div> 

</body> 
</html> 

이의 조각 인 오류입니다. 당신은 공공 또는 정적 폴더에 이미지를 저장할 수

src 
    main 
     resources 
       public 
         img 
         signature.png 

은 모두 thymeleaf을 위해 일하게 될 것입니다 : 이제 프로젝트의 다음 구조를 확인합니다.

0

다음 경로로 이미지를 넣으십시오 src/main/resources/static/img/signature.png.

그런 다음 템플릿에서 다음 URL을 변경합니다

<img src="../static/img/signature.png" th:src="@{img/signature.png}"/> 
+0

이 오류 메시지가 표시되지 않습니다. 정의되지 않은 이미지 파일 ("../static/img/signature.png")이 있습니다. –

+0

Thymeleaf가 구성되어 있는지 확인하십시오. '../static/img/signature.png' URL을 볼 수 없기 때문에 정적 템플릿 개발 중에 만 사용됩니다. Thymeleaf는 적절한 URL을 동적으로 정의해야합니다. – DimaSan

+0

스프링 부트 기본 구성을 사용합니다. 다른 템플릿에서 이미지를 사용할 때 문제없이 작동합니다. 그러나 이메일을 보내기 위해이 템플릿에서 사용할 때 작동하지 않습니다. –