springbootstrap.java

来自「一些很有用的spring的书籍」· Java 代码 · 共 45 行

JAVA
45
字号
package com.apress.springbook.chapter02;

import java.io.FileInputStream;
import java.util.Properties;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.ClassPathResource;

public class SpringBootstrap {
    public static void main(String[] args) throws Exception {

        /* Check if the location of the configuration file has been passed
         * as an argument.
         */
        if (args.length == 0) {
	  throw new IllegalArgumentException("Please provide the location of a " +
	          "Spring configuration file as argument!");
        }

        /* Call the Spring Framework API here! */
        BeanFactory beanFactory = 
	  new XmlBeanFactory(new FileSystemResource(args[0]));

	/*
	BeanFactory beanFactory =
	    new XmlBeanFactory(new ClassPathResource("com/apress/springbook/chapter02/application-context.xml"));
	*/
	//Player player = (Player)beanFactory.getBean("Justine", Player.class);
	

	//System.out.println("Bean property value: " + player.getFullName());

	PropertyEditorTestBean testBean = (PropertyEditorTestBean)beanFactory.getBean("testBean");

        /* pause the application until a key is pressed */
        System.out.println("Press any key to close the application");
        System.in.read();

        /* Key has been pressed, close the application and exit */
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?