I am using spring-boot 2.5.0 and maven as dependency management tool. I have following dependencies as of now in my project.
"<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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>
</dependencies>"
I want to use jsp instead of thymeleaf but when I put my "index.html" file inside templates or static sub-folder of resources folder it doesn't recognize the html file and throws white label error.When I added the thymeleaf dependency it worked perfectly and recognized the html file. So, what should I do to make spring-boot detect my html file without adding thymeleaf dependency. By the way I have never used jsp before.
It seems you are missing either of the two things.
you should put below the property with the desired value in the property/yaml file
spring.mvc.view.prefix: <location of html/jsp>
spring.mvc.view.suffix: <.extension>
check at your controller whether you are sending the correct view name or not.
Related
`I'm using springdoc-openapi. I want to customize the swagger, so I copied the whole thing to my resources directory
I am also not loading the files from the jar
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.6</version>
<exclusions>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
</exclusion>
</exclusions>
</dependency>
But I can't seem to serve any files inside swagger-ui. I tried moving it to static/swagger-ui, but I still get a 404.
When the service starts up, it shows
Patterns [/webjars/**, /**, /swagger-ui*/**] in 'resourceHandlerMapping'
So it looks like openapi is adding those resource paths.
But both http://localhost/index.html and http://localhost/swagger-ui/index.html return 404
I am able to go to http://localhost/hello.html, which is in resources/static, one of the default locations for static files. Why can't I read the index.html file that's in the swagger-ui directory, either in resources/swagger-ui or resources/static/swagger-ui
I need to load a JNDI resource located in a JBoss server. For this, I am using a jnp-client library:
<dependency>
<groupId>jboss</groupId>
<artifactId>jnp-client</artifactId>
<version>4.2.2.GA</version>
</dependency>
The problem is that as soon as I include this dependency in my pom.xml, the Spring application gets stuck at the start time without any message. Not a single line of logs, like if it is trying to load something forever. The main is not even invoked. Removing this dependency the application runs but I get an expected:
ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
Which is normal because I have removed the dependency that includes this class.
Any clue?
I have tried all version of jnp-client or jbossall-client that also includes this NamingContextFactory
EDIT:
It is the mix of these two dependencies that unfortunately are inherited from required dependencies:
<dependency>
<groupId>org.jboss.naming</groupId>
<artifactId>jnp-client</artifactId>
</dependency>
and spring-webmvc inside
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
If I run with
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
</exclusions>
</dependency>
It works fine.
Now, if I exclude the jnp-client I cannot access the JNDI resource, but if I remove the spring-security-web I cannot access the REST endopoints this service exposes.
EDIT2:
So I thought it could be two classes interfering with each other and I started the java process with -verbose. This is what I found.
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$165/0x00000001002d8440
source:
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader
[389.020s][info][class,load]
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$166/0x00000001002d8840
source:
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader
[558.011s][info][class,load]
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$167/0x00000001002d8c40
source:
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader
[558.012s][info][class,load]
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$168/0x00000001002d9040
source:
org.springframework.boot.context.config.ConfigFileApplicationListener$Loader
From time to time the application prints, only in verbose, this ConfigFileApplicationListener$Loader
EDIT 3:
It seems that the problem is TimedSocketFactory inside the jnp-client. Somehow, just by having this class inside the jnp-client dependency, the Spring application is blocked and never starts. Removing this from the jnp-client allows the application to start. Of course, it fails later because the JNDI cannot connect to the server.
I use STS for build a webserver.
I put dependency in pom.xml with this code
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.0.5.RELEASE</version>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
When I run my Webserver with IDE (Spring Tool Suite), if 'html' file which will shown on browser changes, it automatically apply changes.
but if I run it as standalone ( 'mvnw spring-boot:run' ) it doesn't work.
how can I fix this problem?
Currently work with Springframework.boot 2.0.4.RELEASE
In application.properties set:
spring.devtools.restart.exclude=
Default value is (maybe your html file is here):
spring.devtools.restart.exclude=META-INF/maven/**,META-INF/resources/**,resources/**,static/**,public/**,templates/**,**/*Test.class,**/*Tests.class,git.properties
I have the following problem:
I am trying to add a complete bootstrap template to my maven project.
I add the following dependencies to my pom.xml:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
And then I add all files of the template to my folder resources/templates, because I am using thymeleaf.
So the structure of attributes is shown only, but bootstrap design is missing.
Can you help me ? :D
This is how you do it: (I am using Thymeleaf, but this should probably be easy to do even without)
Open the official bootstrap repo: https://getbootstrap.com/docs/4.0/getting-started/download/
Go to Bootstrap CDN and copy the link given in the href attribute: https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css
Open the link in a new tab and copy its contents to your project (preferably in a file under resources/static):
Then, include this file using the link tag in your html files (In my case, th:href): <link th:href="#{/CSS/bootstrap.min.css}" rel="stylesheet">
I've got a Spring Boot app. From what I understand a boot app will only need the dependency in the pom and all is great. Unfortunately, that's not the case and even when I overcomplicate my configuration it still doesn't work - I can't use the sec namespace in my pages.
In my page the first issue is the namespace URI:
I've tried every option available in the Intellij fix menu and can't get it.
I suppose the result of that issue is the fact that I can't use the sec namespace anywhere. The pictured example may indeed be an invalid use but I've used <div> as well which is straight from the Thymeleaf examples:
Many of the answers here and other sources are relying on xml configuration as well, which is of no use. Still, I've made Java-based beans based on those xml examples with no luck.
What steps are required to use spring security and thymeleaf integration in a spring boot app using only Java based configuration (if that)?
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</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.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
...
</dependencies>
I have encountered the same issue and for me it helped to define schema locations like this:
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.thymeleaf.org http://www.thymeleaf.org
http://www.ultraq.net.nz/thymeleaf/layout http://www.ultraq.net.nz/thymeleaf/layout
http://www.thymeleaf.org/thymeleaf-extras-springsecurity4 http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
...
This includes also additional dialects for layout and spring security 4 which you can remove if you are not using them.