Spring5 编译源码 保准让你成功装好

1. 环境准备

工欲善其事,必先利其器。

IDEA 2017.2 、Gradle 4.8、kotlin-plugin-1.2.61-release-IJ2017.2、aspectj-1.9.5.jar

2. 导入Spring5项目

2.1. 科学上网,gradle和maven一样,可以设置工作目录和镜像,在gradle-4.8.1\init.d路径下新建init.gradle文件,如果不设置一下,那是非常慢的,而且容易报错

allprojects{
    repositories {
      def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
    all { ArtifactRepository repo ->
        if(repo instanceof MavenArtifactRepository){
            def url = repo.url.toString()
            if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                remove repo
            }
        }
    }
    maven {
        url REPOSITORY_URL
      }
  }
}

2.2. 导入Spring5项目,git获取或者打开新项目都行

-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m

导好的项目是这样的,如果报错,只是些依赖问题,多试几次

3.编译

3.1.先编译spring-oxm,spring-core

3.2.修改spring-aspects的编译器,AspectJ编译器

1.命令行运行 java -jar aspectj-1.9.5.jar 安装好编译器

2.设置编译器

3.File --> project structure -->Facets-->+-->AspectJ-->spring-apects_main和test都添加进来,并把Kotlin删除

4.build

4.测试

在项目下新建Model,选择gradle-->java,创建相应目录

build.gradle设置依赖

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

User

package com.bpby;

public class User {

	private String userName;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Override
	public String toString() {
		return "User{" +
				"userName='" + userName + '\'' +
				'}';
	}
}

applicationContext.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.xsd">

	<bean id="user" class="com.bpby.User">
		<property name="userName" value="BPBY"></property>
	</bean>
</beans>

Test


public class Test {

	public static void main(String[] args) {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.context");
		System.out.println(applicationContext.getBean(User.class));
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值