gpt4 book ai didi

java - [学习EJB] : annotation type is not applicable to this kind of declaration?

转载 作者:行者123 更新时间:2023-11-30 05:01:05 25 4
gpt4 key购买 nike

尝试使用NetBeans 7.0EJB 3 in Action一书创建最简单的EJB

好吧,首先我创建了一个界面:

package study;

public interface NewInterface {
public void sayHello(String name);
}

然后,EJB:

package study;
import javax.ejb.Stateless;

public class NewClass implements NewInterface{

@Override
@Stateless //! ERROR here !
public void sayHello(String name) {
System.out.println("Hello " + name);
}
}

Java 提示@Stateless

annotation type is not applicable to this kind of declaration

为什么?

最佳答案

应该位于类声明中(而不是方法)。就像这样:

package study;
import javax.ejb.Stateless;

@Stateless
public class NewClass implements NewInterface{

@Override
public void sayHello(String name) {
System.out.println("Hello " + name);
}
}

来自here

关于java - [学习EJB] : annotation type is not applicable to this kind of declaration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6703962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com