Spring Boot Tutorial - Error when trying to check service - spring-boot

I followed steps given in https://spring.io/guides/gs/spring-boot/ for building a springboot application. I am using intellij & Maven, Application started without any errors but when i tried to access hpp://localhost:8080. I am getting an error as below
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Aug 21 08:01:16 IST 2017
There was an unexpected error (type=Not Found, status=404).
No message available

It's mostly likely that either the #RestController or #RequestMapping annotations are missing from your controller class.
You can compare you code to the completed example here, to see if there's anything missing:
https://github.com/spring-guides/gs-spring-boot/blob/master/complete/src/main/java/hello/HelloController.java

Related

Creating security for web application issue in the code for logging into the page

I was building spring security web application using "https://spring.io/guides/gs/securing-web/" but im getting error as " Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Dec 20 11:47:42 IST 2022
There was an unexpected error (type=Internal Server Error, status=500). "pls help!!
i tried to add some jsp dependencies / to use # configuration but still same error and i am expecting the message to be displayed

Swagger-ui error HttpMediaTypeNotAcceptableException

I am trying to add a Spring fox Swagger UI to my existing Spring Boot project.
My issue is that all the paths are working normally like "/v2/api".. except for "/swagger-ui.html".
The error I get everytime is :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Oct 30 11:11:37 CET 2019
There was an unexpected error (type=Not Acceptable, status=406).
Could not find acceptable representation
and the error in debut :
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
When I tried to handle the exception on my Exception Handler, I found that the acceptable type is "application/json" as I use Spring MVC.
Any idea how to resolve that ?
cheers.

automatic configuration of Spring Social’s ConnectController not working

I have followed the steps given in the below site to create a simple spring boot application that access the facebook data using maven and spring boot.
http://spring.io/guides/gs/accessing-facebook/
which is also same as http://www.technicalkeeda.com/spring/spring-social-facebook-integration-example but in gradle.
The problem i am facing is when i am trying to run the application, I have am seeing that url is successfully redirected to "/connect/facebook" but it doesnt load the facebookConnect.html instead it throws error
as shown below:
"
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Mar 10 19:24:41 IST 2015
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported
"
I have also tried using the same code given in the site and also used my facebook appId and appSecret in it , which i had generated by giving a random host name in the facebook app, still i get same error.
I have also tried adding the random host name which i created to the /etc/hosts file in the windows.
Could anyone please help me why i am not able to see the .html page that has to be rendered by the ConnectController automatically ?
I finally got the answer.
it is we need to additional parameter in the application.properties file which is
"spring.social.auto_connection_views=true
along with the id and secret.
spring.social.facebook.appId=
spring.social.facebook.appSecret=
this property was not mentioned in the tutorials. finally this worked. :)
"
Had the exact same issue. spring.social.auto-connection-views: true in the application.yml (or .parameter equivalent) does indeed solve it, but then the default facebookConnect.html and facebookConnected.html are being used.
I solved it by removing the above application parameter and simply adding Thymeleaf tempting engine to the pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
And then you can use your own facebookConnect.html and facebookConnected.html located at src/main/resources/templates/connect/
Hope it can help.

Force Spring to always report exceptions as JSON

How do I force Spring to always convert uncaught exception to JSON instead of HTML page?
This is what I get when request is made from Chrome's REST client plugin:
{
timestamp: 1425041457798
status: 404
error: "Not Found"
exception: "com.some.my.Exception"
message: "/rrr does not exist"
path: "/test/rrr"
}
But this is what I get when I access it from browser or from Jersey API (you see parsed HTML):
Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as a fallback.Fri Feb 27 13:37:27 CET 2015There was an unexpected error (type=Not Found, status=404).No message available
I know this can be done somehow by setting the request headers but I want JSON response to be the only variant.
First we need add some exception resolver for exception that trows inside controllers. I prefer extend ResponseEntityExceptionHandler and add own method, but there is a great article on spring.io: http://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
After that if you still get following page you can override org.springframework.boot.autoconfigure.web.ErrorController. There are an example: BasicErrorController. But this works only if you use spring boot application with embedded container. For example, if you will create war file form spring boot project and will deploy under tomcat, you will get standard tomcat error page.
So this mean that ErrorController is not common solution.
In my case i throws exceptions inside filters, that why /error page shown. So solution will be write own filter that converts exceptions to JSON representation. This solution should work for every container/server, and you can get more information about exception.

Request does not contain Security header, but it's a fault CXF STS Service Client error

I am getting error as provided below:
Jul 06, 2014 3:52:02 PM org.apache.cxf.ws.addressing.soap.MAPCodec restoreExchange WARNING: Response message does not contain WS-Addressing properties. Not correlating response.
Jul 06, 2014 3:52:02 PM org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor handleMessage
WARNING: Request does not contain Security header, but it's a fault.
Jul 06, 2014 3:52:03 PM org.apache.cxf.ws.addressing.ContextUtils retrieveMAPs
WARNING: WS-Addressing - failed to retrieve Message Addressing Properties from context
Exception in thread "main" org.apache.cxf.binding.soap.SoapFault: The signature or decryption was invalid
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:84)
I have some complete example at https://github.com/sampleref/CXFSecurity Please suggest some inputs as it is important for me. Also full details can be found at CXF STS client throws Request does not contain Security header/Response message does not contain WS-Addressing properties
Thanks
I'll put this answer for anyone else who Googles this error and arrives here.
I had the same problem with a JSF2 maven web application running on JBoss Applicatoin server, but I imagine it might happen for many other types of web apps using servlet containers for token-based security (i.e. SAML).
Simply make sure that any passwords you store in configuration files (mine was in standalone.xml) to utilise token-based security are not changed or updated, otherwise this error will occur.

Resources