Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Always externalize bean property values with property placeholders

Instead of placing hard coded values in bean definitions, place property placeholder variables in place of
actual values. That

way, it will be easier to customize system configuration according to the target runtime environment
without requiring any

modifications in the bean configurations.

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="https://www.springframework.org/schema/beans"

xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"

xmlns:context="https://www.springframework.org/schema/context"

xsi:schemaLocation="https://www.springframework.org/schema/beans https://www. ←-

springframework.org/schema/beans/spring-beans.xsd

https://www.springframework.org/schema/context https://www.springframework. ←-

org/schema/context/spring-context.xsd">

<bean id="dataSource" class="org.springframework.jdbc.datasource. ←-

DriverManagerDataSource">

<property name="driverClassName" value="${dataSource.driverClassName}"/>

<property name="url" value="${dataSource.url}"/>

<property name="username" value="${dataSource.username}"/>

<property name="password" value="${dataSource.password}"/>

</bean>

<context:property-placeholder location="classpath:application.properties"/>

</beans>

1.7 Select default version-less XSD when importing namespace definitions

Namespaces are introduced into Spring in order to simplify complex bean configurations, and enable Spring
features in a more

natural way. You need to add namespace XSD into xml configuration files in order to make use of
namespace elements available

in Spring modules as follows.

Figure 1.1: spring namespace xsd versions

<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="https://www.springframework.org/schema/beans"

xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"

You might also like