0

I do not have applicationContext.xml. I don't need it.

This is my web.xml file:

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigurationLocation</param-name>
    <param-value>/WEB-INF/config/security-config.xml</param-value>
  </context-param>
  ...
<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>

I have that security-config.xml file there and it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/security 
        http://www.springframework.org/schema/security/spring-security-3.2.xsd 
        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-3.2.xsd">

    <http auto-config="true">
        <intercept-url pattern="/**" access="ROLE_USER"/>
    </http>
    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="ajde" password="ajde" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>
</beans:beans>

And I still get error like I don't have applicationContext.xml.

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

How is that possible?!?

I can't see what I am doing wrong.

Clearly it is a path. But put to servlet configuration servlet-config.xml under same direcotry works.

I copy/paste my security-config.xml to root of WEB-INF, and I rename it to applicationContext.xml and...IT WORKS!!!!!!

So, wtf I am doing wrong?!?!? I can't see...

enter image description here

luizfzs
  • 1,328
  • 2
  • 18
  • 34
zelenooq
  • 137
  • 1
  • 1
  • 10

1 Answers1

0

From https://docs.spring.io/spring/docs/3.2.5.RELEASE/spring-framework-reference/html/beans.html#context-create

The listener inspects the contextConfigLocation parameter. If the parameter does not exist, the listener uses /WEB-INF/applicationContext.xml as a default. When the parameter does exist, the listener separates the String by using predefined delimiters (comma, semicolon and whitespace) and uses the values as locations where application contexts will be searched. Ant-style path patterns are supported as well. Examples are /WEB-INF/*Context.xml for all files with names ending with "Context.xml", residing in the "WEB-INF" directory, and /WEB-INF/**/*Context.xml, for all such files in any subdirectory of "WEB-INF".

You can avoid applicationContext.xml, but it looks like workround https://www.nurkiewicz.com/2011/01/spring-framework-without-xml-at-all.html

Alexey Semenyuk
  • 3,263
  • 2
  • 32
  • 36
  • I move my config xml to root of WEB-INF folder and I rename it to applicationContext.xml which is default and it works, I know that but why I cant replace that xml and rename it?!? it should work but somehow it doesn't work for me – zelenooq Jul 24 '18 at 18:54