How to Change url localhost spring? - spring

I´m using spring mvc, I have got a project (Apliconta2Web) and your url is //Apliconta2Web/, but if i copy this project and change your name by (Apliconta3WebPrimefaces) when i push button run as i want url //Apliconta3WebPrimefaces/ but always i have got //Apliconta2Web/.
I have changed servlet-name. and add server the name is Apliconta3WebPrimefaces(Apliconta2Web)
How i can change it? Very thank. sorry by my english. i´m learning.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
<display-name>Aplicacion Web Apliconta3WebPrimefaces</display-name>
<servlet>
<servlet-name>apliconta3webPrimeFaces</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/app-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>apliconta3webPrimefaces</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>

Related

How to move web.xml with init-params to Java config?

I am using Spring boot 2.6.3 and I have the following web.xml in my project. What would be the ideal way to move this to Java config?
<web-app version="3.0" 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">
<display-name>My Web Application</display-name>
<servlet>
<servlet-name>my</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.xyz.my.service.custom.config.CustomServiceConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>my</servlet-name>
<url-pattern>/v1/</url-pattern>
</servlet-mapping>
</web-app>
You don't need all of that. Just ditch your web.xml. The AnnotationConfigWebApplicationContext (actually Spring Boot has a specialized sub-class for it) is the default and your configuration class just can be imported or automatically detected
If your #SpringBootApplication annotated class is in the com.xyz.my.service you don't need to do anything. Your CustomServiceConfig will be automatically detected. If it isn't you can add an #Import(CustomServiceConfig.class) to your #SpringBootApplication annotated class.

Servlet mapping specifies an unknown servlet name when use spring4gwt library

I'm trying to integrate GWT and Spring using the library spring4gwt-0.0.1.jar, but get the following error:
Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name springGwtRemoteServiceServlet
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3275)
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3254)
at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1430)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1344)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
My web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>TelephoneBook</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/application-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>>springGwtRemoteServiceServlet</servlet-name>
<url-pattern>/TelephoneBook/springGwtServices/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>TelephoneBook.html</welcome-file>
</welcome-file-list>
</web-app>
What's the matter? Thanks in advance!
Here <servlet-name>>springGwtRemoteServiceServlet</servlet-name> you have an >to much. Is it a copy pase error? (after beginning servlet-name tag

Issue with name appServlet-servlet.xml

Hi guys I'm working with Spring 3.2.3, hibernate 4.2.2 and org.springframework.security 3.0.5. Before I start working with security in spring, my context file was called servlet-context.xml and everything worked fine. Since I start using org.springframework.security 3.0.5 when I try to run my application I get the error:
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/appServlet-servlet.xml]
My web.xml is:
<?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">
<!-- Spring MVC -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet-context.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Notice that I'm specifying my servlet-context.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet-context.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
If I leave my web.xml just like this and copy/paste my servlet-context.xml content in a new file called appServlet-servlet.xml, everything works fine. This is confusing for me since I told web.xml that my context file name was servlet-context.xml. Am I forced to call my context file as appServlet-servlet.xml??. Of course, if I delete servlet-context.xml and leave appServlet-servlet.xml making the specficiation in web.xml, works fine.
I just wanna know if is obligatory to call my context file as appServlet-servlet.xml if I want to use spring security in my app.
This is not strange. Spring works this way. Since your DispatchServlet name is appServlet, Spring automatically tries to find the servlet context that has the same name, here "appServlet-servlet.xml".
Here is a page that may help : http://syntx.io/difference-between-loading-context-via-dispatcherservlet-and-contextloaderlistener/

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