Thymeleaf / Spring Bootアプリで画像を表示できない

maciejd:

私は問題を抱えており、何時間も解決を試みてきましたが成功しませんでした。

Thymeleafを使用してSpring Bootアプリを作成しています。一般的に、index.htmlページにロゴを配置する必要がありますが、まったく表示されません。thymeleafタグの有無にかかわらず、さまざまなuri構成(コードスニペットなど)を試しましたが、どれも機能しませんでした。他のthymeleaf(例:条件文など)タグは正常に機能します-私はそれをテストしましたので、依存関係は原因ではありません。

かつて、jspビューを使用してアプリを作成しましたが、画像に問題はありませんでした。

あなたはどう思いますか、何か不足していますか?

プロジェクト構造

src
 |_main
      |_ java
      |_ resources
               |_ static
                      |_ images
                             |_ logo.png                    
               |_ templates
                      |_ index.html

index.html

<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:replace="fragments/head"></head>

<body>
    <!-- Navigation -->
    <nav class="navbar navbar-light"> <!--style="background-color: blueviolet"-->
        <div class="container">
            <a class="navbar-brand">
                <img th:src="@{~/images/logo.png}">
                MyApplication
            </a>
        </div>
    </nav>
    <img th:src="@{~/static/images/logo.png}">
    <img th:src="@{~/images/logo.png}">

    <img th:src="@{//static/images/logo.png}">
    <img th:src="@{//images/logo.png}">

    <img th:src="@{/static/images/logo.png}">
    <img th:src="@{static/images/logo.png}">
    <img th:src="@{/resources/static/images/logo.png}">
    <img th:src="@{resources/static/images/logo.png}">

    <img th:src="@{//static/images/logo.png}">
    <img th:src="@{//static/images/logo.png}">
    <img th:src="@{//resources/static/images/logo.png}">
    <img th:src="@{/resources/static/images/logo.png}">

    <img th:src="@{src/main/resources/static/images/logo.png}">
    <img th:src="@{/src/main/resources/static/images/logo.png}">

    <img src="/static/images/logo.png">
    <img src="static/images/logo.png">

    <img src="/resources/static/images/logo.png">
    <img src="resources/static/images/logo.png">

    <img src="/main/resources/static/images/logo.png">
    <img src="main/resources/static/images/logo.png">

    <img src="src/main/resources/static/images/logo.png">
    <img src="/src/main/resources/static/images/logo.png">

    <img src="hotelreservation/src/main/resources/static/images/logo.png">
    <img src="/hotelreservation/src/main/resources/static/images/logo.png">

    <img src="D:/Users/Maciek/Documents/git/hotelreservation/src/main/resources/static/images/logo.png">
    <img src="D:\Users\Maciek\Documents\git\hotelreservation\src\main\resources\static\images\logo.png">

<footer th:replace="fragments/footer"></footer>

</body>
</html>


Jアスガロフ:

次のように削除し~ます:

<img th:src="@{/images/logo.png}">

また、Spring Securityを使用している場合は、Security Configurationクラス(WebSecurityConfigurerAdapterを拡張するクラス)でこのメソッドをオーバーライドして、リソースへのリクエストを許可してください。

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Spring Boot、Thymeleaf、@ Controller

分類Dev

Spring Boot、Thymeleaf、@ Controller

分類Dev

Spring Boot Thymeleaf Ajax Call

分類Dev

ThymeleafでSpringブートモデルデータを表示できない

分類Dev

Spring Boot Thymeleafがアラビア語のメッセージを解決できない

分類Dev

Spring Boot + Thymeleaf + webjars Bootstrap 4

分類Dev

Spring Boot-ThymeleafとJQuery?

分類Dev

ThymeleafがSpring-Bootプロジェクト内のテンプレートを検出できない

分類Dev

Spring Boot, Spring Security and Thymeleaf: Apply CsrfFilter to website with form

分類Dev

ログインしていない場合は、Spring Boot / Thymeleafアプリケーションのボタンを非表示にします

分類Dev

nullでないプロパティがnullまたは一時的な値を参照している-Spring Boot-Thymeleaf

分類Dev

Spring Boot、Thymeleafを使用した問題

分類Dev

Spring Controller Thymeleaf 404

分類Dev

Spring Thymeleaf TemplateResolver error

分類Dev

Spring MVC Thymeleaf Kotlin

分類Dev

Spring Thymeleaf TemplateResolver error

分類Dev

Thymeleaf + Spring MVC + Rest

分類Dev

spring mvc 4 + thymeleaf

分類Dev

Spring Boot + Thymeleaf ERROR java.lang.ClassNotFoundException:org.thymeleaf.dom.Attribute

分類Dev

Thymeleaf + Spring、isAuthenticated()/ hasRole()が機能しない

分類Dev

Spring Boot + Thymeleafの@WebAppConfigurationおよび@ContextConfiguration

分類Dev

Spring Boot、作曲クラスのThymeleaf検証

分類Dev

Spring boot 2.0.3 thymeleaf Error Rendering some pages

分類Dev

Spring Boot Ajax post form submit with model and thymeleaf

分類Dev

Spring Boot + ThymeleafのI18n

分類Dev

Spring Boot + Thymeleaf: Bind empty form input to NULL-string

分類Dev

How do I enable Thymeleaf Live Reloading in Spring Boot 1.3

分類Dev

Thymeleaf + Spring Boot: Object creation with related object (Form & Return)

分類Dev

How to use Thymeleaf layout:fragment with Spring Boot properly?

Related 関連記事

  1. 1

    Spring Boot、Thymeleaf、@ Controller

  2. 2

    Spring Boot、Thymeleaf、@ Controller

  3. 3

    Spring Boot Thymeleaf Ajax Call

  4. 4

    ThymeleafでSpringブートモデルデータを表示できない

  5. 5

    Spring Boot Thymeleafがアラビア語のメッセージを解決できない

  6. 6

    Spring Boot + Thymeleaf + webjars Bootstrap 4

  7. 7

    Spring Boot-ThymeleafとJQuery?

  8. 8

    ThymeleafがSpring-Bootプロジェクト内のテンプレートを検出できない

  9. 9

    Spring Boot, Spring Security and Thymeleaf: Apply CsrfFilter to website with form

  10. 10

    ログインしていない場合は、Spring Boot / Thymeleafアプリケーションのボタンを非表示にします

  11. 11

    nullでないプロパティがnullまたは一時的な値を参照している-Spring Boot-Thymeleaf

  12. 12

    Spring Boot、Thymeleafを使用した問題

  13. 13

    Spring Controller Thymeleaf 404

  14. 14

    Spring Thymeleaf TemplateResolver error

  15. 15

    Spring MVC Thymeleaf Kotlin

  16. 16

    Spring Thymeleaf TemplateResolver error

  17. 17

    Thymeleaf + Spring MVC + Rest

  18. 18

    spring mvc 4 + thymeleaf

  19. 19

    Spring Boot + Thymeleaf ERROR java.lang.ClassNotFoundException:org.thymeleaf.dom.Attribute

  20. 20

    Thymeleaf + Spring、isAuthenticated()/ hasRole()が機能しない

  21. 21

    Spring Boot + Thymeleafの@WebAppConfigurationおよび@ContextConfiguration

  22. 22

    Spring Boot、作曲クラスのThymeleaf検証

  23. 23

    Spring boot 2.0.3 thymeleaf Error Rendering some pages

  24. 24

    Spring Boot Ajax post form submit with model and thymeleaf

  25. 25

    Spring Boot + ThymeleafのI18n

  26. 26

    Spring Boot + Thymeleaf: Bind empty form input to NULL-string

  27. 27

    How do I enable Thymeleaf Live Reloading in Spring Boot 1.3

  28. 28

    Thymeleaf + Spring Boot: Object creation with related object (Form & Return)

  29. 29

    How to use Thymeleaf layout:fragment with Spring Boot properly?

ホットタグ

アーカイブ