-1

As per my understanding,

-> define few spring beans in my xml,

-> load that xml inside web.xml, which is available throughout my application

Question is

How the internals bean of Spring initialized, i do not include any xml from Spring, is it through Name Space..??

What triggers Spring internal beans to get loaded/initialized with our application beans.

for eg, to read beans defined in xml file, we provide in web.xml or scan our package and enable component scan, to scan for annotated beans.

But What about Spring beans, beans/classes inside Spring jar.

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
  • Please can you refine your question? What have you tried, and which part do you not understand? – ConMan Jul 01 '15 at 10:27

2 Answers2

0

The Spring-internal beans are initialized whenever a Spring ApplicationContext is set up. This may be done programmatically:

XmlWebApplicationContext appContext = new XmlWebApplicationContext();
appContext.setConfigLocation("/WEB-INF/applicationContext.xml");

Or implicitly by configuring a DispatcherServlet which behind-the-scenes configures a WebApplicationContext

morsor
  • 1,263
  • 14
  • 29
  • You say you "define few spring beans in my xml" and then you say " i do not include any xml from Spring". Posting your code; the web.xml and the Spring XML might make it more clear what you want to know – morsor Jul 01 '15 at 11:12
-1

you can configure Spring in different ways; you can use this one if you don't need Spring MVC

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

or you can use this one if you want to intercept http requests

<servlet>
    <servlet-name>rest</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        your xml(s) here.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

the mapping for the url is the following one:

<servlet-mapping>
    <servlet-name>rest</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

You can also configure Spring without web.xml as described here

These configuration trigger a Spring class (DispatcherServlet, ContextLoaderListener, depending on what you used) that reads the xml files (and or Java classes if you use Spring JavaConfig) and load all the internal spring beans needed to build you application context.

Giovanni
  • 3,951
  • 2
  • 24
  • 30