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



我有一个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发现模式设置为"all"而不是"annotated"。

最新更新