Freemarker template (FTL) not working in struts2 - spring

I am working with Struts2 and ftl. Instead of jsp I want to use ftl, but when I define welcome file in web.xml as login.ftl it is not working. It just shown as text. The entire code is shown in the browser, but if it is jsp everything works.
I just paste my web.xml below.
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>login.ftl</welcome-file>
</welcome-file-list>
How can I configure ftl in Struts2? If I use that same page as output page of an action it is working. How can I solve this? Is there any problem with my web.xml configuration?? Please help me. Thank you in advance.

Maybe this help you(extract of a web.xml):
<servlet>
<servlet-name>freemarker</servlet-name>
<servlet-class>com.thoughtequity.video.web.servlet.SiteFreemarkerServlet</servlet-class>
<!-- FreemarkerServlet settings: -->
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>NoCache</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ContentType</param-name>
<param-value>text/html</param-value>
</init-param>
<!-- FreeMarker settings: -->
<init-param>
<param-name>template_update_delay</param-name>
<param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>number_format</param-name>
<param-value>0.##########</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/te.js</url-pattern>
</servlet-mapping>
<!-- Map *.ftl files to Freemarker-->
<servlet-mapping>
<servlet-name>freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>index.vm</welcome-file>
</welcome-file-list>

FreeMarker template files need to be processed in order to generate textual pages that shows your data. You cannot just put them in welcome-file-list. For example in Struts2 you can redirect to your action and there use your template.
Also read this http://wiki.metawerx.net/wiki/HowToUseAServletAsYourMainWebPage.

Related

Springfox Swagger2 with Spring MVC - 404 Errors

I'm attempting to integrate Springfox Swagger2 into an existing Spring 4 MVC application and running into issues with rendering some of the pages.
The following pages return 404 errors:
https://localhost:9002/swagger-ui.html
Anything under webjars
The following pages work fine and return JSON:
https://localhost:9002/swagger-resources/configuration/security
https://localhost:9002/swagger-resources/configuration/ui
https://localhost:9002/v2/api-docs
I've added the following to my MVC configuration:
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
Going to https://localhost:9002/swagger-ui.html shows a 404 error:
[15/Dec/2017:16:36:07 -0500] "GET /swagger-ui.html HTTP/1.1" 404 36691 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
Going to https://localhost:9002/webjars/springfox-swagger-ui/springfox.js shows the same:
[15/Dec/2017:15:10:08 -0500] "GET /webjars/springfox-swagger-ui/springfox.js HTTP/1.1" 404 36691 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
web.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<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">
<display-name>storefront</display-name>
<!--
We have to explicitly clear the welcome file list.
We don't need to serve a default or index page as we can handle all the requests via spring MVC.
-->
<welcome-file-list>
<welcome-file/>
</welcome-file-list>
<context-param>
<description>
Spring Expression Language Support
</description>
<param-name>
springJspExpressionSupport
</param-name>
<param-value>
false
</param-value>
</context-param>
<!-- filters -->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<!-- set the amount of seconds the conf file will be checked for reload
can be a valid integer (0 denotes check every time,
-1 denotes no reload check, default -1) -->
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>600</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<description>
ResourceFilter
Filter used to server file resources by bypassing the other filters.
</description>
<filter-name>resourceFilter</filter-name>
<filter-class>com.company.storefront.servlets.ResourceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>resourceFilter</filter-name>
<url-pattern>/_ui/*</url-pattern>
<url-pattern>/_public/*</url-pattern>
</filter-mapping>
<filter>
<description>
SSLTerminationFilter
Allows for SSL termination at the loadbalancer/HTTP server level
</description>
<filter-name>SSLTerminationFilter</filter-name>
<filter-class>com.acquitygroup.security.SSLTerminationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SSLTerminationFilter</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<!-- Begin custom security filters -->
<!-- Commented out for fixing log out issue
<filter>
<description>
SecureSessionFilter
Helps prevent session hi-jacking/fixation vulnerabilities
</description>
<filter-name>SecureSessionFilter</filter-name>
<filter-class>com.acquitygroup.security.SecureSessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SecureSessionFilter</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
</filter-mapping>
-->
<filter>
<filter-name>XSSFilter</filter-name>
<filter-class>de.hybris.platform.servicelayer.web.XSSFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>XSSFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter>
<description>
Spring configured based chain of the spring configurable filter beans
</description>
<filter-name>storefrontFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>storefrontFilterChain</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
</filter-mapping>
<filter>
<description>
OpenRedirectInterruptFilter
Helps prevent against Open Redirect vulnerabilities
</description>
<filter-name>OpenRedirectInterruptFilter</filter-name>
<filter-class>com.acquitygroup.security.OpenRedirectInterruptFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenRedirectInterruptFilter</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
</filter-mapping>
<!-- End custom security filters -->
<!-- spring based filter chain -->
<filter>
<description>
SpringSecurityFilterChain
Supports delegating to a chain of spring configured filters. The filter name
must match the bean name.
</description>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
</filter-mapping>
<!-- punchout filter for IE 8 -->
<filter>
<filter-name>P3PFilter</filter-name>
<filter-class>com.company.core.filter.P3PServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>P3PFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- HTTP Session Listeners -->
<listener>
<description>
The HybrisContextLoaderListener extends the usual SpringContextLoaderListener (which loads
the context from specified location) by adding the global application context of
the platform as parent context. With having the global context set as parent you can access
or override beans of the global context and get the 'tenant' scope.
</description>
<listener-class>de.hybris.platform.spring.HybrisContextLoaderListener</listener-class>
</listener>
<listener>
<description>
The RequestContextListener exposes the 'request' scope to the context.
Furthermore it is needed when overriding the 'jalosession' bean for your web application.
</description>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<description>
The RequestContextListener exposes the 'request' scope to the context.
Furthermore it is needed when overriding the 'jalosession' bean for your web application.
</description>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- config -->
<context-param>
<description>
The 'contextConfigLocation' param specifies where your configuration files are located.
The 'WEB-INF/config/web-application-config.xml' file includes several other XML config
files to build up the configuration for the application.
</description>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/config/web-application-config.xml</param-value>
</context-param>
<!-- Servlets -->
<!-- To Avoid server start up issues due to scope tenant -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>de.hybris.platform.spring.ctx.TenantIgnoreXmlWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/config/web-application-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- <servlet>
<description>
DispatcherServlet
Spring MVC dispatcher servlet. This is the entry point for the Spring MVC application.
</description>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<description>
Specifies the location for Spring MVC to load an additional XML configuration file.
Because hybris is already configured with the XML spring configuration files to load
we must set this param value to EMPTY in order to prevent loading of the default
/WEB-INF/applicationContext.xml file.
</description>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> -->
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<!-- Map all requests to the DispatcherServlet -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Uncomment in to enable handling of 500 server errors -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/WEB-INF/views/pages/error/serverError.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/pages/error/serverError.jsp</location>
</error-page>
<!-- handle csrf token errors due to session timeout! -->
<error-page>
<exception-type>com.acquitygroup.security.csrf.RequestConfirmationTokenException</exception-type>
<location>/login?timeout=true</location>
</error-page>
<!-- Session -->
<session-config>
<!-- Session timeout of 30 minutes -->
<session-timeout>240</session-timeout>
</session-config>
<!-- JSP Configuration -->
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<!-- Disable JSP scriptlets and expressions -->
<scripting-invalid>true</scripting-invalid>
<!-- Remove additional whitespace due to JSP directives -->
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
</web-app>
Just looking for some guidance on why this is occurring and how to resolve it.
Please check the aop version, it should be the same version that is 4x. Please refer Integrating Swagger with Spring 3.0.6.RELEASE and https://github.com/springfox/springfox/issues/938. These are the frequent errors in using swagger.

How to set welcome file in spring mvc?

I need to add index.html file as welcome page but the problem is I don't want to add some prefix for appServlet. This is my web.xml file:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I placed index.html file in webbfolder of my project. I believe problem is appServlet mapped to /* and that's why I when I try to reach myDomain/index.html or myDomain/ I get 404 error.

LoggingFilter not invoked - gives HTTP 404 - Not Found error

I am using Jersey 2.3.1, Tomcat 7.0, maven.
I have a simple jersey servlet:
#Path("/myresource")
public class JerseyResource {
#GET
#Produces(MediaType.APPLICATION_JSON)
public List <SecurityControlDTO> getControls() throws HibernateException {
SecurityControlDTOManager manager = new SecurityControlDTOManager();
return manager.getControls();
}
}
And want to add a LoggingFilter.
This is my web.xml:
<!-- Jersey Mapping -->
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.rbs.wisexec.controlservice.rest;</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>jersey-auth</filter-name>
<filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
<init-param>
<param-name>javax.ws.rs.container.ContainerRequestFilter</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jersey-auth</filter-name>
<url-pattern>/rest/*</url-pattern>
<servlet-name>jersey-servlet</servlet-name>
</filter-mapping>
When I run the tomcat server, the server starts up but then when I try to access the URL I get a "HTTP Status 404 - not found" error. I have debug breakpoints in filter class so I can see that it never gets invoked.
I have tried various different ways of configuring the loggingFilter in the web.xml i.e. putting the:
<init-param>
<param-name>javax.ws.rs.container.ContainerRequestFilter</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
Inside of the servlet tag - this runs the server and the resource is shown but again the filters are not invoked.
If you want to configure your application via web.xml and not by using subclass of javax.ws.rs.core.Application, you can modify your web descriptor in this way:
<!-- Jersey Mapping -->
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.rbs.wisexec.controlservice.rest;</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
The important thing is the second init-param which states that LoggingFilter should be added to the list of JAX-RS providers in your application. Parameter is taken from ServerProperties class where you can find description of this parameter (ServerProperties.PROVIDER_CLASSNAMES) as well as other possibilities to configure your Jersey application.

Tomcat migration to WebLogic12

all
Recently I migrate a webapp from tomcat7 to Weblogic12, the jdk version is 1.6.0.30. After I deploy the project war completed, open the login page(/login.htm), ie throw such an exception:
Error 404--Not Found From RFC 2068 Hypertext Transfer Protocol --
HTTP/1.1:
10.4.5 404 Not Found The server has not found anything matching the Request-URI. No indication is given of whether the condition is
temporary or permanent.
If the server does not wish to make this information available to the
client, the status code 403 (Forbidden) can be used instead. The 410
(Gone) status code SHOULD be used if the server knows, through some
internally configurable mechanism, that an old resource is permanently
unavailable and has no forwarding address
.
Here 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">
<display-name>sys</display-name>
<description>JSP application</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/framework-data.xml,
classpath:spring/framework-common.xml,
classpath:spring/framework-query.xml
</param-value>
</context-param>
<!--encoding-->
<filter>
<filter-name>sessionFilter</filter-name>
<filter-class>com.wri.hy.framework.application.framework.security.controller.SessionFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>isCheck</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>*.htm</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.wri.hy.framework.application.framework.security.controller.SessionListener</listener-class>
</listener>
<!--spring-->
<servlet>
<servlet-name>framework</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/framework-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!--surpport WebApplicationContextUtils-->
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!--Watcher-->
<servlet>
<servlet-name>watcher</servlet-name>
<servlet-class>com.wri.hy.framework.application.framework.util.Watcher</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
<url-pattern>/servlet/displayChart</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>framework</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>240</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!--error-page>
<error-code>404</error-code>
<location>/fileNotFound.html</location>
</error-page-->
</web-app>
What can I do for this problem? Here is an active place for puzzles,any response is apprieated. Thanks.
problem resolvered, It sourced by load-on-startup tag value, defined web.xml. Must be different on weblogic.
<servlet>
<servlet-name>framework</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/framework-servlet.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!--surpport WebApplicationContextUtils-->
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Thanks.

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?

This the file web.xml in WEB-INF
<?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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>glpi.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/index.jsp</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>
</web-app>
I think you are missing the context loader listener(to pick your spring context file(s)).
Add this to your web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
You could also check out the Initial web configuration section # http://static.springsource.org/spring/docs/2.0.x/reference/beans.html
You have both ContextLoaderServlet and DispatcherServlet set to load-on-startup = 1. That means either one of them could start first, and you need the ContextLoaderServlet to start first, since that's what creates the root WebApplicationContext that your error says is missing. So leave ContextLoaderServlet's load-on-startup at 1, and change the DispatcherServlet's to 2 or higher.
Actually, it's preferred to use ContextLoaderListener instead of the Servlet unless you're on a really old container where the Listener doesn't work properly.
Add following code in web.xml file, bcs it looks for contex to load so we have to declare it initially.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/HelloWeb-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
I've recently stumbled upon the same issue, and I knew for sure it couldn't be caused by misconfiguration because I've copied the entire working Tomcat installation from another machine. Yet I kept getting the same exception:
java.lang.IllegalStateException: No WebApplicationContext found: not in a DispatcherServlet request and no ContextLoaderListener registered?
As I've eventually figured out, it was a wrong JVM version that broke the application: this one used Java 7, whereas the working instance (and the webapp) was on Java 8.
Hope it helps someone struggling with this counter-intuitive error message.

Resources