美文网首页
JAVA 核心笔记 || [xxx] Spring 之 面世

JAVA 核心笔记 || [xxx] Spring 之 面世

作者: 魔介 | 来源:发表于2018-12-04 12:11 被阅读0次

    目录结构

    目录结构.png

    Say.java

    package com.mj;
    
    public class Say {
    
        private String msg = "=Spring=";
    
        public void setMsg(String msg) {
            this.msg = msg;
        }
    
        public String  talk(){
            System.out.println( msg );
            return msg;
        }
    
    }
    
    

    App.java

    import com.mj.Say;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.context.support.FileSystemXmlApplicationContext;
    
    import java.io.FileNotFoundException;
    
    public class App {
        public static void main(String args[]) throws FileNotFoundException{
            //ClassPathXmlApplicationContext
            ApplicationContext context = new ClassPathXmlApplicationContext("Bean.xml");
            Say sa = (Say) context.getBean("Say");
            sa.talk();
    
            //FileSystemXmlApplicationContext
            ApplicationContext fileContext = new FileSystemXmlApplicationContext("/src/Bean.xml");
    
    
    
            Say sa1 = (Say) fileContext.getBean("Say");
            sa1.talk();
    
        }
    }
    
    
    

    Bean.xml

    <?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-3.0.xsd">
    
        <bean id = "Say" class = "com.mj.Say">
            <property name = "msg" value = "===Spring==="/>
        </bean>
    
    </beans>
    

    运行

    /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58299:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/lib/tools.jar:/Users/mac/d/project/java/mspr/out/production/mspr:/Users/mac/d/project/java/mspr/lib/spring-instrument-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-instrument-tomcat-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-aspects-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-context-support-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-aop-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-jms-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-expression-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-jdbc-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-oxm-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/commons-logging-1.2.jar:/Users/mac/d/project/java/mspr/lib/spring-messaging-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/aopalliance-1.0.jar:/Users/mac/d/project/java/mspr/lib/spring-tx-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-beans-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-orm-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-context-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-core-4.3.18.RELEASE.jar:/Users/mac/d/project/java/mspr/lib/spring-test-4.3.18.RELEASE.jar App
    objc[8456]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x10260b4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1026974e0). One of the two will be used. Which one is undefined.
    Dec 04, 2018 12:10:13 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
    信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@67424e82: startup date [Tue Dec 04 12:10:13 CST 2018]; root of context hierarchy
    Dec 04, 2018 12:10:13 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    信息: Loading XML bean definitions from class path resource [Bean.xml]
    ===Spring===
    Dec 04, 2018 12:10:13 PM org.springframework.context.support.FileSystemXmlApplicationContext prepareRefresh
    信息: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@47c62251: startup date [Tue Dec 04 12:10:13 CST 2018]; root of context hierarchy
    Dec 04, 2018 12:10:13 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    信息: Loading XML bean definitions from file [/Users/mac/d/project/java/mspr/src/Bean.xml]
    ===Spring===
    
    Process finished with exit code 0
    

    相关文章

      网友评论

          本文标题:JAVA 核心笔记 || [xxx] Spring 之 面世

          本文链接:https://www.haomeiwen.com/subject/unhmcqtx.html