How to debug org.thymeleaf.exceptions.TemplateInputException? - java

I have a new project and it's my first time using spring MVC and Thymeleaf.
The error message that I'm getting seems obvious:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers
I have googled a lot and saw many people with similar issues. However, none of the solutions helped me find out why my setup does not work.
Instead of classpath:/templates I have also tried variations like templates and /templates
some questions:
What is the "basedir" from which the relative path is being looked for?
Is it possible to run spring in debug to see how these kind of configurations are set? i.e. call when I call localhost:8080 and there's a breakpoint somewhere: would it be possible to see how the file index.html is being looked for?
edit On line 23 in the document on the right (BetterCommuteApplication.java) you can see that Intellij is able to resolve the reference to my template file.
This screenshot shows my configuration and I think it should suffice as enough information to get the answer.
Thank you for your time! :-)

ugh, I tried to combine Spring boot with thymeleaf manually here.
(I'm used to developing back-ends ^^")
This doesn't make much sense as initialising spring MVC does this right out of the box.
The solution was to init this as springMVC, use #Controller instead of #Restcontroller because I want the class to be handled as MVC class... and the return could be as simple as return 'index' (because my html file in the default location is called index.html)
basically I would have known, if I'd simply followed the tutorial on SpringMVC... but hey, why would anyone RTFM? :-)
so it looks like this:

Related

No endpoint mapping found for `[SaajSoapMessage {http://api.com}getCountryRequest]`

I try to make a Web service using JAVA and SOAP, but every time I try to run the application, I get the following error: No endpoint mapping found for [SaajSoapMessage {http://api.com}getCountryRequest].
I have been attempting to expose listed endpoints like mentioned on Stack Overflow, but has no effect. Furthermore, I also attempted to add the following code to the application.properties file:
spring.webservices.expose-all-endpoints=true
But it doesn't work. Then I set out to add another code to the application.properties file:
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans
But that didn't work either. I have tried many ways to solve this problem for a long time, but I can't find a solution. I will be genuinely grateful if you can help me. Thank you in advance.
Note: To re-create the issue, here is my repo

Basic SpringMvC controller not working

I am trying to set up a basic MVC controller project. I have created a servlet and
couple of jsp pages. I can deploy the project and access the jsp pages.
The problem starts when I try to use the LoginController. The error I am getting is 404 error. Please help.
I have attached a screenshot of my codes and project structure. I gut instinct is the dispatcher servlet is not working the way it suppose to (just a guess).
I have googled and fiddled with the code for the past 5 hours to no avail. This is my first time asking question on S/O enter image description hereso I apologies If this is not in the correct format.
localhost:8084/springmvcDemo/login
change to
localhost:8084/springmvcDemo/spring-mvc/login
This link will help you

Spring Boot Request mapping not loading static resources

I have a spring boot application where I serve some static jsp pages stored in directory src/main/webapp which includes some javascript references stored under directory "src/main/resources/static". When I do the requestmapping for "/somepath" then it successfully returns view that has javascript references in static resources folder such as "src/main/resources/static/lib/script.js"
But the problem that I'm facing right now is when I do the #requestmapping to "/sompath/xyz" then I get HTTP 404 error. When I inspected the page source then I found out that the page was searching for static folder in this path "/somepath/lib/script.js" that is "/somepath" is getting prefixed to the default resources location. Is there any way that I could map these URIs such that no matter how many "/path/" are there, it will look for resources under the "/static/" folder only and not like "/static/path"
Any help is appreciated. I apologise for my problem structure as I'm a beginner and I'm still learning to put all these things in better perspective. Thanks in advance.
I have same problem I found the way but its half solution.
first
use RequestMapping path depth just one like 'spring'
It is work well every situation.
second
use RequestMapping path depth tow like 'spring/xyz' and <link src="../some.css"/>
last
use depth 3 'spring/xyz/123' and <link src="../../some.css"/>
This all is messed up but it is working.
So I open the question on stack overflow again here please anyone come and check this and leave some idea thanks~!

Spring MVC, how to include another controller/view inside a view (partialview)

I'm just starting out with Spring MVC having been trying to pickup Java(Web) for the few months.
I'm sure what I'm trying to achieve is very simply, but I can't find a solution that really works.
I'd like to include another controller/view inside a view. This could be a menu, or some other dynamically generated content. For example, let's say in a side bar of an application I need to display a list of categories. I don't want to have to retrieve these categories in every controller/view that needs to use them. I'd like to include another controller/view into the main page view so that this content can be placed in multiple views but managed by a single piece of code.
ASP.NET MVC has something called PartialViews, and most PHP frameworks seem to offer this kind of functionality, but I can't find anything like this in spring.
The closest I've come to resolving this issue is to use the jsp:include tag, which does work, infact it's almost the solution, but it generates errors in Eclipse because obviously Eclipse can't locate the path, as it's a spring RequestMapping i.e. /include/categories rather than a direct link to a physical file.
The other solution is to use Javascript to dynamically load content into the sidebar, but I don't want to do that.
Is there a 'correct' way to do this, or is there a way to supress the errors generated by eclipse for the jsp:include tag?
If the content your are including is static and you don't have a lot of different pages, your approach with including jsps is ok. Otherewise, look at the templating frameworks like Tiles or Thymeleaf.

You don't have permission to access /schema/beans/spring-beans-3.1.xsd on this server

I am using spring framework in one of my application. It was working fine till now. But today in morning when I tried to run my application, it was throwing errors for not able to intialise spring framework. So I tried loading xsd files in the browser but in vain because it was showing forbidden page to me. And the page contains "You don't have permission to access /schema/beans/spring-beans-3.0.xsd on this server". I even tried loading 3.1 xsd, 2.5 xsd but not able to access any of them and showing same error page.
I know, I must download xsd and put them into my classpath but i haven't done and now i got this.
Can anyone please help me out of this? Or if any body has 3.0 xsd then can you please give it to me.
I want following xsds:
spring-beans-3.0.xsd
spring-context-3.0.xsd
spring-mvc-3.0.xsd
and xsds that are being called by the above one internally.
Thank you every one.
The XSD files are included in the Spring JAR files, so you already have them. For example, spring-context-3.0.xsd is inside spring-context.jar, in the org/springframework/context/config package. The spring-beans.xsd is in spring-beans.jar (org/springframework/beans/factory/xml package) and I'll leave finding the last one as an exercise to the reader.
I had the same problem, it appears that the public schemas on the internet are unavailable. I found those spring-beans-2.5.0.xsd and save it in a directory of my app.
I changed the schema location to use the xsd on the path I gave it e.g. (WEB-INF/xml/spring-beans-2.5.0.xsd)
http://www.springframework.org/schema/beans/spring-beans-2.5.0.xsd
to
WEB-INF/xml/spring-beans-2.5.0.xsd
and that fixed it.
Public Schema was unavailable. It has been restored. Don't know where to look for status, but it's working now.
I faced with the same issue today. The problem was that versions of XSD's and the Spring library in classpath were incompatible (3.0 vs 2.5.5 in my case). I fixed XSD versions in my spring XML's and it works fine now

Categories

Resources