I have created an web application based on spring mvc After I deployed it, in Tomcat manager the application is shown and it has been deployed successfully. But when I am accessing the web application it is giving me error saying requested resource is not available.
In log files there are no errors so far. Please help.
Regards,
Shruti
As you are using Spring MVC,
You should have SpringController in your project.
So in your each controller -
for each method there should be
a #RequestMapping(value = "/login", method = RequestMethod.GET) portion.
So your application url should be something like -
<<web server address>>/<your deployed war file name>/<The Request mapping url>
i.e.
something like -
http://localhost:8080/samplewebproject/login
which will give you the requested resource.
Related
I am using Kotlin + Gradle and trying to build a war file to deploy on Tomcat. My application is from the https://start.spring.io plus a simple controller and build the war file using ./gradlew bootWar
#SpringBootApplication
class ServletInitializer : SpringBootServletInitializer() {
override fun configure(application: SpringApplicationBuilder): SpringApplicationBuilder {
return application.sources(DemoApplication::class.java)
}
}
#RestController
class TomcatController {
#GetMapping("/hello")
fun sayHello(): Collection<String> {
return IntStream.range(0, 10)
.mapToObj { i: Int -> "Hello number $i" }
.collect(Collectors.toList())
}
}
when I try to access it I get
Type Status Report
Message The requested resource [/demo-0.0.1-SNAPSHOT/hello] is not available
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
I am super stuck. What am I doing wrong? If I add a html file to the src/main/webapp/index.html it shows up for some reason only the rest api can't be reached.
Spring Boot applications come with a built in Servlet. You are probably already using this feature when launching the application inside your IDE.
This basically means that you can just run your .jar file on any web server and it will be ready to go without setting up an extra tomcat instance.
However, if you want to build a Spring Boot application as a war file and deploy it to an external tomcat, you need to follow some extra steps as explained in this article.
Assuming from what you posted so far: the path that is returned shows another route before your actual controller route "/demo-0.0.1-SNAPSHOT/hello" is this "/demo-0.0.1-SNAPSHOT" the path that your application runs on ? If not it should be included in your controller (assuming you havent set it elsewhere for e.g. in your application.properties).
for e.g. http://localhost:8080/ would be the basepath and either http://localhost:8080/demo-0.0.1-SNAPSHOT/hello or http://localhost:8080/hello would point to your controller. Also your startup logs (for Tomcat and Spring) might give away more about the issue.
I'm seeking for a help with an issue I'm facing with Zuul which is not working on Tomcat being packaged into WAR.
Standalone it works perfectly well, but when I change packaging to war and deploy to Tomcat - requests does not seem to reach Zuul.
I have extended SpringBootServletInitializer and overridden configure() method, but that does not help.
Note: please do NOT advise me to run SpringBoot standalone with embedded Tomcat - that does not work as I need to incorporate an API gateway into existing infrastructure set up. In other words I need to implement a gateway given a boundary condition - it has to be deployed on Tomcat application server.
#SpringBootApplication
#EnableZuulProxy
public class GatewayApplication extends SpringBootServletInitializer {
...
#override
protected StringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(GatewayApplication.class);
}
}
application.yml
zuul:
routes:
freebeer:
path: "/beer/**"
url: "https://freedom.com:443"
default:
path: "/**"
url: "http://landing.com/"
It works perfectly fine when I'm running standalone app with embedded Tomcat e.g.:
- request to http://localhost:8080/ is nicely redirected to http://landing.com/
- as well as ..:8080/beer is nicely redirected to freedom.com
But in case of WAR deployed to Tomcat - nothing works:
- request to http(s)://tomcat.intranet.com:12345 welcomes me with message that nothing is there and suggests to add web content
- request to http(s)://tomcat.intranet.com:12345/beer gives me 404 with message that origin server did not find a current representation for the target resource or that it's not willing to disclose that one exists
Looks like I'm missing something very obvious. But I've run out of patience to figure it out and calling for help :)
Resolved. Requests were simply sent to wrong context - to app server root instead of web app specific. I solved it by naming war as ROOT.war
How do we handle incoming request to a wrong contextpath in spring mvc?
I have deployed a spring mvc application having contextpath as
http://exampledomain.com/mycontext
But when I try accessing url http://exampledomain.com/wrongcontext I get error as HTTP Status 404 - /wrongcontext/
I have implemented error handling which works fine for all wrong url when correct context path is used but it does not work for wrong context path.
I am trying to understand how do we redirect all incoming request to specific page in production environment..
thanks in advance
Your application can only see requests to its context /mycontext There is nothing your application can do about requests to other contexts.
You can however deploy an application at the root context / and implement an error handler there.
Check out this answer: How to customize JBoss AS7 404 page
That answer relates to JBoss, but the same idea will apply on other servers.
It is not possible to handle wrong context path requests in Spring since it only will handle the requests which goes to your context root. You have to take a look at server configuration parameters to redirect those kind of requests. If you are working on Tomcat, check path parameter of context.xml:
https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Defining_a_context
We can use #ExceptionHandler inside a #Controller or #ControllerAdvice to handle such kind of exceptions and decide on the view page to be rendered.
#ExceptionHandler({ HttpRequestMethodNotSupportedException.class,
HttpMediaTypeNotSupportedException.class, HttpMediaTypeNotAcceptableException.class,
MissingPathVariableException.class, MissingServletRequestParameterException.class,
ServletRequestBindingException.class,MethodArgumentNotValidException.class, MissingServletRequestPartException.class,
NoHandlerFoundException.class})
public ModelAndView handleException(){
return new ModelAndView("errorpage");
}
We have a soap-webservice defined through the Spring(spring-ws) and Spring is generating the wsdl through our config. And we have defined the end-point in our code as:
wsdl11Definition.setLocationUri(http://xyz:8080/dev/ws/abc);
and so the wsdl got generated with the Spring is :
http://xyz:8080/dev/ws/def.wsdl
and the below is what am seeing as the endpoint in the generated wsdl
<soap:address location="http://xyz:8080/dev/ws/abc"/>
But our clients are able to access our service with both of the below.
http://xyz:8080/dev/ws/def.wsdl http://xyz:8080/dev/ws/abc.
How does this work or is working.
Does Spring/tomcat routes or able to route the web-service calls coming in with either the endpoint-path of .wsdl name (def in above) too and also the one with the endpoint (abc in the above) to the end soap web service.
please share any insights, if any have on this. thanks much.
I just got done with a new Web module built with Spring Framework. Till now I was testing all the pages on my local machine using Tomcat. Today after I moved the application to Websphere,
I am getting the following error:
Error 404: No target servlet configured for uri
is there anything I need to do in web.xml or somewhere? I deployed an EAR file on my WAS , which has another war file.
Below is the output I am seeing on the console, if thats any help.
The resource WEB-INF/ibm-web-bnd.xmi that is defined in URI WEB-INF/ibm-web-bnd.xmi for module analytics.war is not valid. The resource has a cross reference org.eclipse.jst.j2ee.webapplication.internal.impl.WebAppImpl#4be44be4 (eProxyURI: WEB-INF/web.xml#WebApp_ID) that cannot be resolved.
[6/17/09 15:24:49:465 CDT] 00000011 ArchiveDeploy W ADMA0091E: The resource WEB-INF/ibm-web-ext.xmi that is defined in URI WEB-INF/ibm-web-ext.xmi for module analytics.war is not valid. The resource has a cross reference org.eclipse.jst.j2ee.webapplication.internal.impl.WebAppImpl#7b7a7b7a (eProxyURI: WEB-INF/web.xml#WebApp_ID) that cannot be resolved.
It looks like you haven't got your servlet configured correctly. I'd say your web.xml has a servlet-name entry that doesn't correspond to a -servlet.xml file in your WEB-INF directory.
I got same error for my json response. This is fixed by setting contentLength in the action.
ibm-web-bnd.xmi has an attribute: fileServingEnabled.
This controls if Websphere is serving static content or not (index.html, pictures, etc.).
It is true, by default if omitted, but you can make sure it is on by adding it to tag WebAppExtension
fileServingEnabled="true"