赞
踩
compile "org.springframework:spring-context:4.3.9.RELEASE"
compile "org.springframework:spring-beans:4.3.9.RELEASE"
compile "org.springframework:spring-core:4.3.9.RELEASE"
compile "org.springframework:spring-expression:4.3.9.RELEASE"
group 'com.gradle.kotlin'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.2-5'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'war'
repositories {
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.springframework:spring-context:4.3.9.RELEASE"
compile "org.springframework:spring-beans:4.3.9.RELEASE"
compile "org.springframework:spring-core:4.3.9.RELEASE"
compile "org.springframework:spring-expression:4.3.9.RELEASE"
testCompile group: 'junit', name: 'junit', version: '4.11'
}
<?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">
</beans>
group 'com.gradle.kotlin'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.2-5'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'war'
apply plugin: 'kotlin-noarg'
apply plugin: 'kotlin-allopen'
noArg{
annotation("com.kotlin.annotations.Bean")
}
allOpen{
annotation("com.kotlin.annotations.Bean")
}
repositories {
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.springframework:spring-context:4.3.9.RELEASE"
compile "org.springframework:spring-beans:4.3.9.RELEASE"
compile "org.springframework:spring-core:4.3.9.RELEASE"
compile "org.springframework:spring-expression:4.3.9.RELEASE"
testCompile group: 'junit', name: 'junit', version: '4.11'
}
package com.kotlin.annotations
annotation class Bean
noArg{
annotation("com.kotlin.annotations.Bean")
}
allOpen{
annotation("com.kotlin.annotations.Bean")
}
package com.kotlin.Bean
import com.kotlin.annotations.Bean
@Bean
data class Student(var name: String)
<bean id="student" class="com.kotlin.Bean.Student"/>
package com.kotlin
import com.kotlin.Bean.Student
import org.springframework.context.support.FileSystemXmlApplicationContext
import org.junit.Test
class main
{
@Test
fun test()
{
//加载Spring配置文件,创建对象
val context = FileSystemXmlApplicationContext("src/main/webapp/WEB-INF/applicationContext.xml")
val student = context.getBean("student") as Student
println(student)
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。