我尝试在我的应用中使用注释。我在docs中创建了界面,但找不到MappingJackson2HttpMessageConverter.class。你能告诉我为什么吗?找不到EvenList:/
@Rest(converters = { MappingJackson2HttpMessageConverter.class })
public interface MyRestClient {
@Get("http://company.com/ajax/services/events")
EventList getEvents();
}
注释工作正常。我的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.example.package.name'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.example.package.name"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}
答案 0 :(得分:1)
Android Annotation REST API是Spring Android RestTemplate模块的包装器。 因此,您需要将android spring dependencies添加到您的gradle文件中。
dependencies {
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
}repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
另外,请不要忘记将以下行包含在您的实现类
中 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;