Working on sample spring boot application using spring-boot-starter-parent 2.0.5 with security. Main spring boot application class extends SpringBootServletInitializer. War file generated and works fine in tomcat. I deployed same war file on websphere application server and the application starts but it looks like spring boot is not getting initialized. I don't see any error in log. Is thre anything should be done for the application to initialize in websphere?
The issue is resolved by updating web.xml from
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
to latest format
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsc"
id="webApp_ID" version="3.1">
<display-name>Archetype Created Web Application</display-name>
</web-app>
Related
im learning SpringMVC, and find this problem, project running well, but this is irritating
I think the web.xml is in wrong place
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
this line in web.xml is giving error.
you just have to delete these lines from the file "web.xml"
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
When i try to run this project i received following error
"org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping for GET /DemoSpringMaven/add".
Error
org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping for GET /DemoSpringMaven/add
Web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>frontcontroller</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>frontcontroller</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
WEB-INF/frontcontroller-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.fazaal"></context:component-scan>
</beans>
Controller/AddController.java
package com.fazaal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class AddController {
#RequestMapping("/add")
public void add() {
System.out.println("I am Here!");
}
}
First, all these web.xml, servlets' XML configurations, manual setting of chains - this is the last age, sorry. Spring hid all these configurations inside own framework and you can use just very convenient annotations. One application class, one configuration class - and the web application works! And if you are a newbie in Spring, Spring MVC or JSP/Servlets, or you need to start your application ASAP, or you need a platform from which you want to start the framework learning, just use Spring Boot.
Second, if you want to leave your configuration ... how will MVC know about mapping /DemoSpringMaven/add? You specified just /add. Add full mapping or add global controller #RequestMapping("/DemoSpringMaven").
Try this servlet mapping:
<servlet-mapping>
<servlet-name>dispatcher-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Also the method should have #ResponseBody before it (probably this it the source of the issue):
#ResponseBody
#RequestMapping("/add")
public void add() {
System.out.println("I am Here!");
}
But as Dmitry Ionash said, this is really old way how to build Spring web applications. Try Spring Boot: https://spring.io/guides/gs/rest-service/
I'm working on the Spring MVC "FitnessTracker" application outlined on Pluralsight. Below is my "web.xml" file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>fitTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>/FitnessTracker/*.html</url-pattern>
</servlet-mapping>
<display-name>Archetype Created Web Application</display-name>
</web-app>
The above makes Tomcat generate a bunch of exceptions, starting with
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
But when I change what's between the <url-pattern> tag to *.html, it works fine. Why is that?
Note: My goal is to try to make my app's controller run when I type /FitnessTracker/greeting.html, instead of /greeting.html. I am using Intellij IDEA, and doing Maven project with Tomcat 7.0 as my server.
Application runs # http://localhost:9090/FitnessTracker/greeting.html URL . FitnessTracker is application root context and greeting.html is mapped to Hello controller method. Please see below.
Could you please post the web.xml and controller mapping .
The original code runs at the URL - http://localhost:8080/FitnessTracker/greeting.html. SO I am not sure why you need to change web.xml for that.
Also the URL pattern you are trying to use "/FitnessTracker/*.html" is not valid.
More details here.
https://stackoverflow.com/a/5441862/6352160
I have a webapp with Maven which uses Tomcat plugin for the server. The app gets compiled to .war which, when extracted, seems to contain all classes (incl. servlets) in WEB-INF/classes folder.
When the url http://localhost:8080/com.galya.crm gets hit, index.html (which is a SPA app) gets loaded normally redirecting to http://localhost:8080/com.galya.crm/#!/login/msg/notlogged
I have 4 servlets annotated in a similar manner:
#WebServlet("/restapi/login")
public class LoginController extends HttpServlet {
The problem comes when the SPA app tries to authenticate using the login servlet (shown above). I expect it to be here: http://localhost:8080/com.galya.crm/restapi/login , but I get 404 error.
Below I attached the Tomcat plugin folder that is automatically created. Work directory is empty and I'm not sure if it's OK.
Initially the webapp/WEB-INF/web.xml was auto generated and contained the following:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
I also tried to change it to accept WebServlet annotations, but didn't work also:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>
P.S. The app was working on another server some time ago, so the problem should be in the server configurations, not in the code itself.
Surely the cause is that the deployment descriptor must be declared to be of version 3.0. Your web.xml is still 2.3.
Remove the DOCTYPE declaration and leave the root node just as you already did:
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
Tested myself, and it worked.
Thanks to the UNUSUAL deployment of Tomcat6 I need to deploy my web app that is using the Spring & Hibernate on a server where access to the WAR deployment's web.xml at /webapps/MyDeployment/WEB-INF/web.xml is not allowed.
So I need to know if such a deployment is even possible, Where we will initialize the spring framework in the serever's web.xml at /webapps/WEB-INF/web.xml and not use the WAR's web.xml ?
Below is the WAR's web.xml that I am currently using at my environment,
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>abcd</display-name>
<!--Here we specify about the DispatcherServlet class in the Web Deployment
Descriptor -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.abcd</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.xyz</url-pattern>
<url-pattern>*.pqr</url-pattern>
</servlet-mapping>
Unfortunately changes in the Tomcat configuration is not allowed,
Any suggestions will be highly appreciated.
Thank you for all your help, but we ended up solving the problem by asking the server administrator to lift some of the restrictions that had been put regarding file access to the tomcat user.
Now we can access the domain web xml aswell as the server web xml.