我在为ccF REST服务API项目集成enunciate和ant时遇到错误。方法getFeeItemsByCapID()中存在错误。我尝试在源代码中找到答案,但没有结果。谁对错误有任何想法?谢谢你的帮助。如果您有任何提示。
Ant脚本
<path id="enunciate.classpath">
<fileset dir="${enunciate.home}/lib">
<include name="*.jar"/>
</fileset>
<!--include (optional) spring module-->
<fileset dir="${enunciate.home}/lib/modules/cxf">
<include name="*.jar"/>
</fileset>
<fileset dir="${java.home}">
<include name="lib/tools.jar"/>
</fileset>
</path>
<taskdef name="enunciate" classname="org.codehaus.enunciate.main.EnunciateTask">
<classpath refid="enunciate.classpath"/>
</taskdef>
<enunciate basedir="java/" configFile="enunciate.xml">
<include name="**/*.java"/>
<classpath refid="enunciate.classpath"/>
<export artifactId="war.file" destination="d:/myapp.war"/>
<javacArgument argument="-g"/>
</enunciate>
Enunciate.xml
<?xml version="1.0"?>
<enunciate label="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
<namespaces>
<namespace id="api" uri="http://api.example.com/" />
<namespace id="link" uri="http://api.example.com/link" />
<namespace id="persona" uri="http://api.example.com/persona" />
</namespaces>
<modules>
<!-- Docs -->
<docs splashPackage="org.codehaus.enunciate.api" title="test" copyright="test.com"/>
<java-client disabled="false"/>
<amf disabled="true"/>
<c disabled="true"/>
<obj-c disabled="true"/>
<csharp disabled="true"/>
<spring-app disabled="false"/>
<cxf disabled="false"/>
<gwt disabled="true"/>
<jaxws-ri disabled="true"/>
<jersey disabled="true"/>
</modules>
Java代码
@GET
@RecordDetailSecurity(RecordDetailSectionType.FEE)
@Path("/{recordIds}/fees/")
@Produces(MediaType.APPLICATION_JSON)
@JsonView(Views.PublicView.class)
public ResponseModel getFeeItemsByCapID(@PathParam("recordIds") String recordIds,
@QueryParam("fields") @DefaultValue("") String fields) throws Exception
{
例外:
java.lang.IllegalStateException: D:\AA7.2.0\main-dev\biz\modules\rest-apis\java\com\accela\restapis\jaxrs\agency\service\FeeWebService.java:76: the element 'value' must have a value specified.
at net.sf.jelly.apt.decorations.declaration.DecoratedAnnotationMirror.<init>(DecoratedAnnotationMirror.java:66)
at net.sf.jelly.apt.decorations.DeclarationDecorator.decorate(DeclarationDecorator.java:362)
at net.sf.jelly.apt.decorations.DeclarationDecorator.decorateAnnotationMirrors(DeclarationDecorator.java:113)
at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotationMirrors(DecoratedDeclaration.java:213)
at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotations(DecoratedDeclaration.java:195)
at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotation(DecoratedDeclaration.java:225)
at org.codehaus.enunciate.contract.jaxrs.ResourceMethod.<init>(ResourceMethod.java:130)
at org.codehaus.enunciate.contract.jaxrs.Resource.getResourceMethods(Resource.java:143)
at org.codehaus.enunciate.contract.jaxrs.Resource.<init>(Resource.java:69)
at org.codehaus.enunciate.contract.jaxrs.RootResource.<init>(RootResource.java:34)
at org.codehaus.enunciate.apt.EnunciateAnnotationProcessor.getRootModel(EnunciateAnnotationProcessor.java:214)
at org.codehaus.enunciate.apt.EnunciateAnnotationProcessor.process(EnunciateAnnotationProcessor.java:103)
at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(AnnotationProcessors.java:60)
at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:258)
at com.sun.tools.apt.main.Main.compile(Main.java:1102)
at com.sun.tools.apt.main.Main.compile(Main.java:964)
at com.sun.tools.apt.Main.processing(Main.java:95)
at com.sun.tools.apt.Main.process(Main.java:85)
at com.sun.tools.apt.Main.process(Main.java:67)
at org.codehaus.enunciate.main.Enunciate.invokeApt(Enunciate.java:777)
at org.codehaus.enunciate.main.Enunciate.doGenerate(Enunciate.java:366)
at org.codehaus.enunciate.main.Enunciate$Stepper.step(Enunciate.java:1735)
at org.codehaus.enunciate.main.Enunciate$Stepper.stepTo(Enunciate.java:1767)
at org.codehaus.enunciate.main.Enunciate.execute(Enunciate.java:174)
at org.codehaus.enunciate.main.EnunciateTask.execute(EnunciateTask.java:156)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
源代码:
public DecoratedAnnotationMirror(AnnotationMirror delegate) {
if (delegate == null) {
throw new IllegalArgumentException("A delegate must be provided.");
}
this.delegate = delegate;
AnnotationType annotationType = delegate.getAnnotationType();
Collection<AnnotationTypeElementDeclaration> allElements = annotationType.getDeclaration() != null? annotationType.getDeclaration().getMethods() : Collections.<AnnotationTypeElementDeclaration>emptyList();
Map<AnnotationTypeElementDeclaration, AnnotationValue> elementValues = getElementValues();
put("annotationType", annotationType);
put("position", delegate.getPosition());
put("elementValues", elementValues);
allElementValues = new HashMap<String, Object>();
for (AnnotationTypeElementDeclaration element : allElements) {
if (elementValues.containsKey(element)) {
Object value = elementValues.get(element).getValue();
allElementValues.put(element.getSimpleName(), value);
put(element.getSimpleName(), value);
}
else {
AnnotationValue defaultValue = element.getDefaultValue();
if (defaultValue == null) {
throw new IllegalStateException(delegate.getPosition() + ": the element '" + element.getSimpleName() + "' must have a value specified.");
}
答案 0 :(得分:0)
我在自定义注释中找到了根本原因。看来因为注释没有默认值。当我删除方法的自定义注释或在注释定义中附加默认值时。例外将消失。但是注释接受枚举,在业务逻辑中没有默认值的注释。我们总是需要为使用设置枚举值。但是,为什么注释总是需要默认值?有人知道原因吗?
@Target( {ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface RecordDetailSecurity
{
RecordDetailSectionType value(); //append default value such as "default RecordDetailSectionType.ADDITIONAL_INFORMATION;"
}
@RecordDetailSecurity(RecordDetailSectionType.FEE)
public ResponseModel getFeeItemsByCapID(@PathParam("recordIds") String recordIds,
@QueryParam("fields") @DefaultValue("") String fields) throws Exception
答案 1 :(得分:0)
关于注释默认值错误,我创建了一个示例项目再试一次。它运作良好。现在,我需要改变我原来的意见。我的错。 :) 首先,我的项目编译是成功的,之前没有发出ant目标。但是,枚举“RecordDetailSectionType”实际上属于另一个jar。 我没有包含jar来声明类路径,因此enunciate无法识别自定义的注释类型值。对不起有误。