Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法识别Java注释_Java_Spring_Spring Boot_Annotations_Spring Tool Suite - Fatal编程技术网

无法识别Java注释

无法识别Java注释,java,spring,spring-boot,annotations,spring-tool-suite,Java,Spring,Spring Boot,Annotations,Spring Tool Suite,我有一个spring启动应用程序,使用@PreAuthorize进行安全检查。如果我通过执行gradle任务bootRun启动应用程序,则验证在应用程序中有效。如果我从Spring工具套件(使用标准运行配置)启动应用程序,安全检查将不起作用 我认为问题在于,从STS开始时,预授权注释无法识别。我可以使用与实际应用程序相同的继承层次结构,用一个简单的gradle spring启动应用程序复制它 “DemoEntity”扩展了“BaseDemo”,后者扩展了“AbstractBaseEntity”

我有一个spring启动应用程序,使用@PreAuthorize进行安全检查。如果我通过执行gradle任务bootRun启动应用程序,则验证在应用程序中有效。如果我从Spring工具套件(使用标准运行配置)启动应用程序,安全检查将不起作用

我认为问题在于,从STS开始时,预授权注释无法识别。我可以使用与实际应用程序相同的继承层次结构,用一个简单的gradle spring启动应用程序复制它

  • “DemoEntity”扩展了“BaseDemo”,后者扩展了“AbstractBaseEntity”
  • “DemoService”扩展了“AbstractService”,后者实现了“IEntityService”
  • “DemoService”实现了“IDemoService”,它扩展了“IEntityService”
以下是相关代码:

public class DemoEntity extends BaseDemo {}
public class BaseDemo extends AbstractBaseEntity {}
public abstract class AbstractBaseEntity {}

public class DemoService extends AbstractService<BaseDemo, DemoEntity> implements IDemoService {
    @Override
    @DemoAnnotation
    public void create(DemoEntity entity) {}
}

public interface IDemoService extends IEntityService<DemoEntity> {}

abstract class AbstractService<B extends AbstractBaseEntity, E extends B> implements IEntityService<E> {
    @Override
    public void create(E entity) {
        throw new UnsupportedOperationException();
    }
}

public interface IEntityService<E> {
    void create(E entity);
}

@Retention(RetentionPolicy.RUNTIME)
public @interface DemoAnnotation {}
从gradle任务启动运行开始时,我得到以下结果:

Method: public void com.example.annotationdemo.DemoService.create(java.lang.Object)
  #Annotations: 1
  Annotation: @com.example.annotationdemo.DemoAnnotation()

Method: public void com.example.annotationdemo.DemoService.create(com.example.annotationdemo.AbstractBaseEntity)
  #Annotations: 1
  Annotation: @com.example.annotationdemo.DemoAnnotation()

Method: public void com.example.annotationdemo.DemoService.create(com.example.annotationdemo.DemoEntity)
  #Annotations: 1
  Annotation: @com.example.annotationdemo.DemoAnnotation()
继承层次结构中的每个方法都有注释。 从STS启动应用程序时,结果是:

Method: public void com.example.annotationdemo.DemoService.create(com.example.annotationdemo.DemoEntity)
  #Annotations: 1
  Annotation: @com.example.annotationdemo.DemoAnnotation()

Method: public void com.example.annotationdemo.DemoService.create(com.example.annotationdemo.AbstractBaseEntity)
  #Annotations: 0

Method: public void com.example.annotationdemo.AbstractService.create(java.lang.Object)
  #Annotations: 0
我认为这个演示重现了我在实际应用程序中遇到问题的原因。 我使用SpringBoot2.2.0和Java11创建了带有SpringInitializer的项目,并且没有其他依赖项

有谁能告诉我,为什么STS除了运行bootRun之外还会产生其他结果?
我是否需要在STS中添加参数或设置,使其与bootRun的行为相同?

注释不会在树中继承。所以我实际上希望STS的结果是实际的结果,而另一个结果(bootRun)是错误的。只有方法
create(DemoEntity)
被注释,其他方法没有注释。确保您使用的是相同的JDK和相同的版本。我同意。但这也意味着我还没有发现我真正的应用程序的问题。在我的实际应用程序中,注释检查安全性,从STS开始时,安全性检查被忽略。该方法是通过一个自动连接的IDemoService调用的(我实际上有一个DemoService对象)。如果我将代码更改为直接自动连接DemoService(而不是其接口),则安全检查有效。注释不会在树中继承。所以我实际上希望STS的结果是实际的结果,而另一个结果(bootRun)是错误的。只有方法
create(DemoEntity)
被注释,其他方法没有注释。确保您使用的是相同的JDK和相同的版本。我同意。但这也意味着我还没有发现我真正的应用程序的问题。在我的实际应用程序中,注释检查安全性,从STS开始时,安全性检查被忽略。该方法是通过一个自动连接的IDemoService调用的(我实际上有一个DemoService对象)。如果我将代码更改为直接自动连接DemoService(而不是它的接口),那么安全检查就会起作用。
Method: public void com.example.annotationdemo.DemoService.create(com.example.annotationdemo.DemoEntity)
  #Annotations: 1
  Annotation: @com.example.annotationdemo.DemoAnnotation()

Method: public void com.example.annotationdemo.DemoService.create(com.example.annotationdemo.AbstractBaseEntity)
  #Annotations: 0

Method: public void com.example.annotationdemo.AbstractService.create(java.lang.Object)
  #Annotations: 0