Why Deployment Descriptor: Archetype Created Web Application, appears in every packages in SpringMVC package? - spring

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>

Related

Spring Boot on Websphere application server 9

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>

Why does my Spring MVC application not work when changing the server mapping?

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

Spring Websocket, 404 error while connecting. App not using Spring MVC

I'm trying to get working the Spring Example tutorial:
https://spring.io/guides/gs/messaging-stomp-websocket/
But I need it working on an existing Application that I need to add WebSocket support. The idea is once I get the basic working, start building from there.
The differences I have with the example in the URL is:
I'm not using SpringBootApplication, but Tomcat instead (7.0.69)
That implies I do have a web.xml (included below)
I skipped the Application.java with the main... I'm building a WAR and deploying it manually into Tomcat.
Whem I start Tomcat I read the following which seems relevant:
03:06:52,908 INFO SimpleBrokerMessageHandler:157 - Starting...
03:06:52,908 INFO SimpleBrokerMessageHandler:260 - BrokerAvailabilityEvent[available=true, SimpleBrokerMessageHandler [DefaultSubscriptionRegistry[cache[0 destination(s)], registry[0 sessions]]]]
03:06:52,913 INFO SimpleBrokerMessageHandler:166 - Started.
The problem is the following:
When I click on connect on the index.html, I get a 404 when I'm trying to reach the server at the mapping url "/hello" (not sure why info is there, I guess is part of the protocol..) http://localhost:8080/hello/info
I was googling this, even found some answers in stackoverflow. Some have fixed this addding as prefix the DispatcherServlet mapping to the websocket url...
However my app isn't using Spring MVC, so I don't have a DispatcherServlet configured... and I looks like an overkill to include it just for the WebSockets.
I tried adding the annotation #EnableWebMvc to the WebSocketConfig class (in the link is the code, I have the same lines)
Any suggestion will be much appreciated !
WEB.XML
<?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_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>App</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
I give up trying to avoid having an MVC Dispatcher for an APP witch doesn't use Spring MVC.
This solved it:
web.xml
<servlet>
<!-- Only used by websockets -->
<servlet-name>SpringMVCDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/websockets-application-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVCDispatcherServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
And then, in the index.html I only added the prefix /ws/ when connecting (only there, sinding messages without the prefix is ok).

Can I initialize Spring via Tomcats web xml (../webapps/WEB-INF/web.xml)?

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.

servlet mapping is shown as the project name on the URL. do i need ibm-web-bnd.xmi?

I have created a servlet mapping as /reskilling in my Servlet class. When I run the application the url contains the project name instead. This is a WebSphere Web application which is part of my EAR project. Do i need ibm-web-bnd.xmi to fix this?
here's my web.xml
<display-name>HibernateReskillingWeb</display-name>
<servlet>
<description>Paid Up Plan List</description>
<display-name>PaidUpPlanServlet</display-name>
<servlet-name>PaidUpPlanServlet</servlet-name>
<servlet-class>za.co.test.PaidUpPlanServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PaidUpPlanServlet</servlet-name>
<url-pattern>/reskilling</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
The erros information is shown below ...
HTTP Error Code: 404
Error Message:JSPG0036E: Failed to find resource /HibernateReskillingWeb/views/PaidUpPlan.jsp
Root Cause:java.io.FileNotFoundException: JSPG0036E: Failed to find resource /HibernateReskillingWeb/views/PaidUpPlan.jsp at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.findWrapper(AbstractJSPExtensionProcessor.java:395)...
What is the context root for this web application? From the error message it is HibernateReskillingWeb
If you haven't done anything to the Context Root, the default value is the Dynamic Web project's name.
You can see this value in the application.xml and you can change that to anything that you want.
Is there a directory called views under which your JSPs are stored? That is where the Container is looking for your JSP.
The servlet mapping (that you have shown) has got no role to play here as you are trying to access a JSP.
HTH

Resources