go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Way#3 Spring Bean by Annotation
 
Subject: Way#3 Spring Bean by Annotation
Author: WebSpider
In response to: Way#2 Spring Bean by Java Configuration
Posted on: 10/20/2019 10:58:10 PM


The POJO class

package com.example.spring.model;

import org.springframework.stereotype.Component;

@Component
public class Sex_Annotation_Bean {
	
	private String sex;
	
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
}


The auto-detect configuration component-scan
<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>
    
    <context:component-scan base-package="com.example.spring" />
	
</beans>



 

> On 10/20/2019 10:55:50 PM WebSpider wrote:


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();
	}
}





References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.