How can I set the prefix path(set the new directory) to render the HTML page?
I have a spring boot application. I am using version 2.1.7.
I am set a new path for view page.
Add the following line in Application.properties
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/views/ #this is the main
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
spring.main.allow-bean-definition-overriding=true
You can use basic setup or by overriding a property in application.properties to give your own customise page.
A prefix that gets prepended to view names when building a URL.
spring.thymeleaf.prefix=classpath:/config/templates/
Related
I want to display the image after an error has occurred in my spring boot application. I read the documentation and tried several ways and it still doesn't work.
I read the documentation and tried several ways and it still doesn't work.
I try this:
<img th:src="#{/images/error_image.jpg}"/>
and this:
<img src="../static/images/error_image.jpg" th:width="1000" th:src="#{/images/error_image.jpg}"/>
This is my project structure:
project structure
Hovering over a photo with ctrl directs me to a photo, so the path is good.
link
but all the time I see this:
error
[EDIT]
The issue is with below controller method, you should provide mapping below.
#GetMapping // add mapping here
public String showSignUpForm()
{
return "register";
}
Make sure static resource is not configured to different path other static/ at your end.
If you have below configuration in application.properties, remove it.
spring.resources.static-locations=
Make sure you have below configurations in application.properties, spring boot's auto-configuration will set it to resource/static/
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
It's not an issue but still, change /images/ to images/
<img src="../static/images/error_image.jpg" th:width="1000" th:src="#{images/error_image.jpg}"/>
Is there anyone can tell me how to add SameSite:Strict to all cookies created in spring 5.1? I know in spring 4, this attribute was not supported. But since Spring 5.1, It can be as declare at here!
But I don't know how to apply this to my project? Where should I put it? Please help me! Thanks!
I cannot add SameSite attribute to my project using Spring because Object javax.servlet.http.Cookie hasn't supported this attribute. But I could custom cookie header in Apache tomcat (version 9.0.11) by add the following line to conf/context.xml:
<Context allowCasualMultipartParsing="true">
...
<CookieProcessor className="org.apache.tomcat.custom.coyote.TomcatCoyoteCustomer"/>
</Context>
And then create a project "CustomCookieProcessor" with TomcatCoyoteCustomer class that extends Rfc6265CookieProcessor class, override method generateHeader and append "SameSite:Strict" to cookie header. Finally, I copy jar file of "CustomCookieProcessor" project to folder lib of Tomcat. You can read more detail about CookieProcessor of Apache Tomcat at here!
I have spring boot project in IntelliJ IDEA by maven and when I want create jsp page like name"index.jsp" it being disable and not active as jsp page please help.
How can I solve that problem?
inside /src/main/resources/application.properties (if you dont have this file craete it)
append the following:
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
please note your jsp must be inside WEB-INFF/jsp/ folder, if you want it in another folder just change the value of this property
In spring boot , there is an property file application.property, along with this property , I have created an extra property file named myownprop.properties.
How can I load myownprop.properties in application.property? means how to include another named properties in application.properties?
any update ?
You could use the spring.config.additional-location property as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files. It allows you to add additional files without messing with the nice default hierarchy of property sources that Spring Boot defines.
You could add a new active profile in your current application.properties
spring:
profiles:
active: dev, additional
and then add a new application-additional.properties file in your resource folder. The entries within the new file are then available as they are in the application.properties.
How to provide Hibernate Search parameters when using Spring Boot?
...
spring.datasource.driverClassName=org.postgresql.Driver
hibernate.search.jmx_enabled=true
hibernate.search.default.directory_provider=filesystem
hibernate.search.generate_statistics=true
hibernate.search.lucene_version=LUCENE_CURRENT
hibernate.search.default.indexBase=/mypath-to-index
It does not care what I provide. Default settings always get applied.
I think below code does not have anything to process properties related to Hibernate Search. Can that be the issue?
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java
You can put them in the application.properties file if you put "spring.jpa.properties." in front of the property names.
Example:
spring.jpa.properties.hibernate.search.jmx_enabled=true
spring.jpa.properties.hibernate.search.default.directory_provider=filesystem
spring.jpa.properties.hibernate.search.generate_statistics=true
spring.jpa.properties.hibernate.search.lucene_version=LUCENE_CURRENT
spring.jpa.properties.hibernate.search.default.indexBase=/mypath-to-index
Spring will take any properties under spring.jpa.properties.* and pass them along (with the prefix stripped) once the EntityManagerFactory is created.
Got it working.
Put another property file named "hibernate.properties" inside src/main/resources with below content.
hibernate.search.jmx_enabled=true
hibernate.search.default.directory_provider=filesystem
hibernate.search.generate_statistics=true
hibernate.search.lucene_version=LUCENE_CURRENT
hibernate.search.default.indexBase=/mypath-to-index