@JavaScript没有注释类型

时间:2019-03-05 13:55:10

标签: javascript java eclipse annotations vaadin

我在Java项目中收到此错误消息。怎么解决?我只是构建Vaadin的标准原型应用示例。我想尝试将JavaScript包含到我的项目中。但是简单的注释已经给出了错误消息:@JavaScript没有注释类型

我尝试了这个:项目->属性-> JavaCompiler-> AnnotationProcessing->启用仍然是一个错误。也许我必须包含某些.jars?

enter image description here

代码如下:

package my.vaadin.app;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

import com.vaadin.annotations.*;



/**
 * This UI is the application entry point. A UI may either represent 
 * a browser window 
 * (or tab) or some part of an HTML page where a Vaadin application 
 * is embedded.
 * <p>
 * The UI is initialized using {@link #init(VaadinRequest)}. This              
 * method is intended to be 
 * overridden to add component to the user interface and initialize 
 * non-component functionality.
 */

@Theme("mytheme")
@JavaScript("javascript-test.js")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();

        final TextField name = new TextField();
        name.setCaption("Type your name here:");

        Button button = new Button("Click Me");
        button.addClickListener(e -> {
            layout.addComponent(new Label("Thanks " + name.getValue() 
                    + ", it works!"));
        });

        layout.addComponents(name, button);

        setContent(layout);
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", 
    asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode =         
    false)
    public static class MyUIServlet extends VaadinServlet {
    }
}

2 个答案:

答案 0 :(得分:1)

尝试通过以下方式导入它:

import com.vaadin.ui.JavaScript;

答案 1 :(得分:0)

奇怪的是,这的确是缺失的进口。我改变了

import com.vaadin.annotations.*;

import com.vaadin.annotations.JavaScript;

,并且有效。我还包括了

<swagger-core-version>1.5.15</swagger-core-version>

在属性和

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>${swagger-core-version}</version>
</dependency>

进入pom.xml