0

I'm trying to solve a problem with a project made with Spring Boot (Thymeleaf). When I run the project (run as Spring Boot App), the project starts but when I open the browser I can see the following layout:

enter image description here

The result I'd have to see is this one: see

If, into the folder of my project on Eclipse, I right-click on the index.html page and I select "Open With" and "Web browser", the website's layout is shown in the right way.

This is the structure of my project:

see

And here the stylesheet css on the index page: enter image description here

Am I doing something wrong?

Here the dependencies of my project:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <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>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.4</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
Count
  • 9
  • 2
  • You have shown us what you see, but what do _expect_ to see? I'm guessing here: are you saying that one or more CSS resources are not getting applied? You can [edit] your question to clarify. – andrewJames Jun 25 '22 at 19:34
  • 1
    Please also consider taking the [tour] and reading [ask] for more background. – andrewJames Jun 25 '22 at 19:34
  • @andrewJames thanks for the answer. I edited my comment, hoping that in this way my problem is more clear. Yes, once I run the project on Eclipse, the CSS resources are not applied by going on the browser at "localhost:8080". But if I right click on the index.html and I open it with the web browser the CSS are applied. – Count Jun 26 '22 at 10:02

1 Answers1

0

it seems that you are trying to access your assets and that they won't load properly when starting the application.

I had a similar problem when trying to load images.

In case you haven't done that yet, you will need to configure which static resources Spring will load once the application starts.

I recommend trying the accepted answer in this post: Spring Boot unable to serve static image from resource folder

Hope it helps