标签:生成 字符 pki actor 名称 version 多个 ann 定义
<?xml version="1.0" encoding="UTF-8"?> <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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <bean id="myBean" class="com.lpkienge.MyBean"/> </beans>
这样一个最简单的bean就配置好了
package com.mibloom; import org.springframework.stereotype.Component; /** * @Auther: LPKIENGE * @Date: 2018/10/29 17:33 * @Description: */ @Component public class MyBean { private String name = "MIBLOOM"; public String getName() { return name; } public void setName(String name) { this.name = name; } }
自动装配只适合那些自己定义的组件,第三方类库中的组件是没办法自动装配的(难道你要在源码上加注解?)所以只能用XML或者JavaConfig配置。
package com.mibloom; import com.mibloom.lpk.Bloom; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @Auther: LPKIENGE * @Date: 2018/11/3 10:55 * @Description: */ @Configuration public class JavaConfig { @Bean public MyBean myBean(){ return new MyBean(); } @Bean public Bloom bloom(){ Bloom bloom = new Bloom(); bloom.setName("THIS IS MY BLOOM"); return bloom; } }
标签:生成 字符 pki actor 名称 version 多个 ann 定义
原文地址:https://www.cnblogs.com/mibloom/p/9878638.html