Subject: Way#2 Spring Bean by Java Configuration
Author: WebSpider
In response to: Way#1 Spring Bean by XML Configuration
Posted on: 10/20/2019 10:55:50 PM
The POJO class
package com.example.spring.model;
public class Address_Configure_Bean {
private String address;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
The Java configuration
package com.example.spring.model;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class BeanConfig {
@Bean
public Address_Configure_Bean getConfigBasedBean(){
return new Address_Configure_Bean();
}
}
>
> On 10/20/2019 10:54:49 PM
WebSpider wrote:
The POJO class
package com.example.spring.model;
public class Name_XML_Bean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The XML configuration file app-config.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean name="myXmlBean" class="com.example.spring.model.Name_XML_Bean"></bean>
</beans>
References: