I'm trying to configure a Spring Boot application with JSP template. I'm having some problems with it so I'm comparing my application with Spring Boot's sample jsp application: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp
To my surprise I've got the same problem with the sample. I'm going to try to describe the steps I've followed:
Download spring-boot: git clone https://github.com/spring-projects/spring-boot
Move to a stable version: git checkout v1.4.0.RELEASE
Move to the sample application: cd spring-boot/spring-boot-samples/spring-boot-sample-web-jsp/
Run the application: mvn spring-boot:run
In the application's logs I see the available request mappings: /, /foo and /error
I do this request curl -XGET localhost:8080/ and I get this answer:
{"timestamp":1471504557212,"status":404,"error":"Not Found","message":"No message available","path":"/"}
The result that I expected was the html of welcome.jsp. It seems that there is a problem when Spring Mvc tries to render welcome.jsp.
Any idea what I am doing wrong?
Related
I followed the instructions on https://quarkus.io/get-started/ and build this demo using the latest quarkus(2.7).
My java environment is:
when I run quarkus dev it turns out fine like this:
But when I access http://localhost:8080/hello I got an 404 like this:
I should have got a string "Hello RESTEasy" as the demo code is like:
Can any one tell me why would this happen?
I have a spring boot application bundled as war file , and able to push to App Engine
But I am getting problems starting app (I suspect there could be an issue with DB too...but couldnt remember where I saw...a nightmare)
java.lang.RuntimeException: java.lang.IllegalStateException: Logback
configuration error detected: ERROR in
ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Failed to
create parent directories for
[/base/data/home/apps/e~pemy/20210716t001812.436581063072799646/logs/pynew.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] -
openFile(logs/pynew.log,true) call failed.
java.io.FileNotFoundException: logs/pynew.log (No such file or
directory)
I am using the below properties in my application props
> logging.file.path=logs
> logging.file.name=${logging.file.path}/pynew.log
I am finding it very hard to include google specific dependencies and properties , and making a mess of my project...created app.yaml, web-inf>> appengine-web xml, logging.properties (not sure why but added as told in a tutorial)
Question: How can I create parent directory or link to cloud storage folder etc?
I also want to specify a profile and I see I can do it in yaml file. Is this used only
env_variables:
JAVA_USER_OPTS: '-Dspring.profiles.active=prod'
But I would like to know how to connect to Cloud SQL
spring.datasource.url=jdbc:mysql:///mydb?cloudSqlInstance=myapp:europe-west2:dBinstancename&socketFactory=com.google.cloud.sql.mysql.SocketFactory
spring.datasource.username=${dbuser}
spring.datasource.password=ENC(${dbencpwd})
spring.cloud.gcp.sql.database-name=mydb
spring.cloud.gcp.sql.instance-connection-name=myapp:europe-west2:dBinstancename
It is so confusing that I keep forgetting which connection needs password and which wont. and keep breaking my local
Question
Assuming that I need to supply credentials, How can I supply - ${dbuser}
I used the default spring logger with logback-spring.xml for all my development, and this is not working on AppEngine
So I followed https://cloud.google.com/logging/docs/setup/java
and added logback.xml and the dependency
implementation 'com.google.cloud:google-cloud-logging-logback:0.121.3-alpha'
I want to validate xml against schema - using SpringBoot 2 and camel 3.
On localhost this works:
.to("validator:file:src/main/resources/D.xsd")
But when uploaded to server on tomcat machine with context for example D - i get an error:
Caused by: java.io.FileNotFoundException: src/main/resources/D.xsd (No such file or directory)
I think that i need to change the path to use classpath - but i am not sure how to make it work ?
What i tried:
.to("validator:file:classpath:/src/main/resources/D.xsd")
.to("validator:file:resource:classpath:src/main/resources/D.xsd")
.to("validator:file:resource:classpath:/src/main/resources/D.xsd")
But it does not work.
In one of my applications (but with SpringBoot 1.5 and Camel 2.x) this works fine
.to("validator:classpath:folder/filename.xsd")
to validate against filename.xsd that is located in src/main/resources/folder
I've managed to fix it with:
.to("validator:D.xsd")
My app works just fine if I run the application on my host using the
mvn spring-boot:run
but when I deploy it on docker, it does not work and I get this error:
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/store/index", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/store/index", template might not exist or might not be accessible by any of the configured Template Resolvers
but if I go on the url: http:localhost:8080/login which is controlled by spring security, renders the template normally. Seems to be a permission problem but I'm not sure.
here is my Dockerfile:
FROM openjdk
VOLUME /tmp
RUN touch engdevcommerce.jar
COPY target/engdevcommerce.jar engdevcommerce.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/engdevcommerce.jar"]
Solution:
Turns out the problem I was having, had nothing to do with the docker deployment. I ran the jar file on my host, and I was getting the same error.
The problem was that, where I returned the view url at the controllers methods, I was starting with slash like this: "/.../..." . And spring does not load view with double slash when the application is packed as .jar file. I had to remove the slash character at the beginning of the url every where I returned a ModelAndView and at the th:insert tags too on my html files.
this link helped me a lot :
spring-boot-thymeleaf-not-resolving-fragments-after-packaging
Always check the application execution first with 'java -jar your_app_name.jar' command!
In general this issue is mostly resolved by checking following 3 points-
Your application.properties should have the entry-
spring.thymeleaf.prefix=classpath:/templates/
Your controller should return name of the template without any preceding slash. As the thymeleaf configuration is case sensitive.
Your Project should follow standard spring boot thymeleaf directory structure. If not, then make changes accordingly in your application.properties file.
add your local index directory to dockerfile so it will create /store and copy the index directory to /store then your docker vm will have /store/index with the contents from you local index directory
...
...
ADD <local-index-directory> /store
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-
jar","/engdevcommerce.jar"]
I'm trying to create a config file in yaml for my Spring Boot project.
For a test I just setup some values:
user:
test: hello
Now I'm trying to get the information of user.test, but I get the error message Could not resolve placeholder 'user.test' in value "${user.test}"
The strange thing is, that if my config files just has user.test: hello, then everything works fine.
Is there something that I have to setup before to work with yml files as properties?