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));
}
}