• spring源码学习2


    1、创建Demo项目

    创建一个Gradle Module ![](https://img2018.cnblogs.com/blog/1373276/201903/1373276-20190306163342459-1119854604.png)

    2、修改build.gradle

    build.gradle 需要添加以下依赖(PS:网上关于这块的帖子实在太少了,调试过程中各种报错,本人走了不少弯路才总结出来的,目前最新版的spring至少要以下5种依赖) ``` plugins { id 'java' }

    group 'org.springframework'
    version '5.2.0.BUILD-SNAPSHOT'

    sourceCompatibility = 1.8

    repositories {
    mavenCentral()
    }

    dependencies {
    compile(project(":spring-beans"))
    compile(project(":spring-core"))
    compile(project(":spring-expression"))
    compile(project(":spring-context"))
    compile(project(":spring-instrument"))
    testCompile group: 'junit', name: 'junit', version: '4.12'
    }

    创建一个service类
    

    package com.springsource;

    public class LoginService {

    public String login(String username){
    	System.out.println(username + "登录...");
    	return "success";
    }
    

    }

    
    applicationContext.xml
    

    <bean id="loginService" class="com.springsource.LoginService"/>
    
    ``` 创建测试类: ``` package com.springsource;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;

    public class Test {
    public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    LoginService service = (LoginService)context.getBean("loginService");
    service.login("admin");
    }
    }

    <h1>3、运行</h1>
    运行测试类,成功!
    ![](https://img2018.cnblogs.com/blog/1373276/201903/1373276-20190306173358492-288823965.png)
    
    最终的项目结构如下:
    ![](https://img2018.cnblogs.com/blog/1373276/201903/1373276-20190306172634015-877189142.png)
  • 相关阅读:
    Android ListView常用用法
    android ListView详解
    /使用匿名内部类来复写Handler当中的handlerMessage()方法
    android Handler的使用(一)
    Android之Handler用法总结
    动态设置android:drawableLeft|Right|Top|Bottom
    Android Drawable Resource学习(十)、ScaleDrawable
    Android开发——关于onCreate的解读
    onCreate()方法中的参数Bundle savedInstanceState 的意义用法
    Android之drawable state各个属性详解
  • 原文地址:https://www.cnblogs.com/lmj612/p/10483254.html
Copyright © 2020-2023  润新知