Results 1 to 5 of 5

Thread: beans vs beans:beans namespace?

  1. #1
    Join Date
    Apr 2009
    Posts
    12

    Default beans vs beans:beans namespace?

    Hi -

    I've created my project from the sprint templates available in sts. These templates include a servlet-context.xml that declares the beans namespace as beans:beans rather than just plain beans.

    On the other hand, the root-context is just plain beans and most of the project examples I see or download use just plain beans. I have xsd problems if I try to change it to plain beans.

    Can anyone explain what is going on? Thanks.

    Peter

  2. #2

    Default

    Hi Peter,

    depending on the template you select, it will be the default name space used in the servlet-context.xml

    For instance, if you select the spring-mvc template, then you'll get the next:
    Code:
    <beans:beans xmlns="http://www.springframework.org/schema/mvc"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    Please note the default name space is that of mvc. Therefore you may just start adding <validator>, <resources>, and so on.

    In case you want beans to be default, then you need to change both the xmlns, remove the beans and add the mvc, like this:
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    Hope it helps.

    Carlos.

  3. #3
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    286

    Default

    These templates include a servlet-context.xml that declares the beans namespace as beans:beans rather than just plain beans.
    This means the default namespace is not "beans", it is something else (i.e mvc, security)

    I have xsd problems if I try to change it to plain beans.
    How a look at following example,

    Default is "security"
    Code:
    <beans:beans xmlns="http://www.springframework.org/schema/security"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
    
    
    	<authentication-manager alias="authenticationManager">
    		<authentication-provider>
    			<user-service>
    				<user name="admin" password="admin" authorities="ROLE_ADMIN" />
    				<user name="user" password="user" authorities="ROLE_USER" />
    			</user-service>
    		</authentication-provider>
    	</authentication-manager>
    </beans:beans>
    Converted to "beans"
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
    
    
    	<security:authentication-manager alias="authenticationManager">
    		<security:authentication-provider>
    			<security:user-service>
    				<security:user name="admin" password="admin" authorities="ROLE_ADMIN" />
    				<security:user name="user" password="user" authorities="ROLE_USER" />
    			</security:user-service>
    		</security:authentication-provider>
    	</security:authentication-manager>
    </beans>
    According to example, if you have a lot of security related code, it is easier when the security namespace is the default.
    Amila Domingo

  4. #4
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    286

    Default

    Didn't see Carlos's reply
    Amila Domingo

  5. #5
    Join Date
    Apr 2009
    Posts
    12

    Default

    Ah and now I see the light... This was really tripping me up as I'm pretty new. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •