转载

装配bean

通过XML装配bean

通过set注入

强依赖构造,可选属性通过set注入

package com.ming;

import java.util.List;

public class BlankDisc implements CompactDisc {
    private String title;
    private String artist;
    private List<String> tracks;

    public void setTitle(Str-ing title) {
        this.title = title;
    }

    public void setArtist(String artist) {
        this.artist = artist;
    }

    public void setTracks(List<String> tracks) {
        this.tracks = tracks;
    }

    public String getTitle() {
        return title;
    }

    public String getArtist() {
        return artist;
    }

    public List<String> getTracks() {
        return tracks;
    }

    /**
     * 规定方法为play
     */
    @Override
    public void play() {
        for(String track: tracks){
            System.out.println(track);
        }
    }

}
package com.ming;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.junit.Assert.*;

public class BlankDiscTest {
    ApplicationContext applicationContext = null;

    @Before
    public void setUp() throws Exception {
        applicationContext = new ClassPathXmlApplicationContext("ApplicationConfig.xml");
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void play() {
        BlankDisc blankDisc = (BlankDisc) applicationContext.getBean("reallyBlackDisc");
        assert blankDisc != null;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="reallyBlackDisc" class="com.ming.BlankDisc"/>
</beans>

此时为空,初始化列表

使用列表

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="reallyBlackDisc" class="com.ming.BlankDisc">
		<property name="title" value="ming"/>
		<property name="artist" value="mingxiao"/>
		<property name="tracks">
			<list>
				<value>ming</value>
				<value>xiao</value>
				<value>xiaomingming</value>
			</list>
		</property>
	</bean>
</beans>

使用命名空间

<?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:P="http://www.springframework.org/schema/c"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="reallyBlackDisc" class="com.ming.BlankDisc" p:title = "mingxiao" p:artist="xiaoming"
	>
		<property name="tracks">
			<list>
				<value>ming</value>
				<value>xiao</value>
				<value>xiaomingming</value>
			</list>
		</property>
	</bean>
</beans>

剩下的时间干什么

剩下的时间做这些

  1. php + thinkphp 这个需要符合要求
  2. 性能测试 vbscript 等等一票需要完成
    3

java的最后一阶段呢 暑假开学,,两个月足够了,,,这个课程本身就是4个月就能学完的。。

java需要除了spring boot 还需要什么 shiro csv 这两个 搜索引擎 等等一堆,,足够了,,,两个月的时间

原文  https://www.iming.info/zhuang-pei-bean/
正文到此结束
Loading...