繁体   English   中英

javax.ws.rs.core.Application 构造函数调用了两次

[英]javax.ws.rs.core.Application constructor called twice

我有一个 Jax-Rs 应用程序,我试图理解为什么我的应用程序初始化程序被调用了两次。

这是初始化器:

@ApplicationPath("/rest")
public class JaxRsActivator extends Application {

    private static final Logger logger = LogManager.getLogger();

    private Set<Object> singletons = new HashSet<Object>();
    private HashSet<Class<?>> classes = new HashSet<Class<?>>();

    public JaxRsActivator() {
        CorsFilter corsFilter = new CorsFilter();
        corsFilter.getAllowedOrigins().add("*");
        corsFilter.setAllowedMethods("OPTIONS, GET, POST, DELETE, PUT, PATCH");
        singletons.add(corsFilter);
        singletons.add(new CacheManager());

        classes.add(RequestMetadataFilter.class);
        classes.add(ResponseMetadataFilter.class);

        classes.add(CommonController.class);
    }   

    @Override
    public Set<Object> getSingletons() {
        return singletons;
    }

    @Override
    public HashSet<Class<?>> getClasses(){
      return classes;
    }
}

这是 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>MyApp</display-name>
    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
    <error-page>
        <error-code>403</error-code>
        <location>/error-403.jsp</location>
    </error-page>
</web-app>

我正在使用 Java 8 在 Wildfly 14 上运行它。

我不确定,但我认为问题出在 beans.xml 上,它的 bean-discovery-mode 设置为“all”而不是“annotated”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM