装配bean

栏目: Java · 发布时间: 4年前

内容简介:强依赖构造,可选属性通过set注入此时为空,初始化列表剩下的时间做这些

通过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 这两个 搜索引擎 等等一堆,,足够了,,,两个月的时间


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms on Strings, Trees and Sequences

Algorithms on Strings, Trees and Sequences

Dan Gusfield / Cambridge University Press / 1997-5-28 / USD 99.99

String algorithms are a traditional area of study in computer science. In recent years their importance has grown dramatically with the huge increase of electronically stored text and of molecular seq......一起来看看 《Algorithms on Strings, Trees and Sequences》 这本书的介绍吧!

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具