在tomcat 9,Java8 -〉没有问题。
我正在升级到tomcat 10,Java 16
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.0</version>
</dependency>
这是我的beans.xml
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd"
version="3.0"
bean-discovery-mode="all">
</beans>
Session.java:
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.ws.rs.ForbiddenException;
import jakarta.ws.rs.core.SecurityContext;
/**
* セッションインターフェース
*/
@SuppressWarnings("serial")
@SessionScoped
public class Session implements Principal, SecurityContext, Serializable, Map<String, Object> {
/**
* インスタンスを取得
*
* @return インスタンス
*/
public static Session current() {
try {
return CDI.current().select(Session.class).get();
} catch (Exception e) {
return new Session();
}
}
Main.java:
@Inject private Session session;
@GET @Path("index.html") public Object index() {
if (session.getCategoryCode() != null) {
return Response.temporaryRedirect(URI.create("menu.html")).build();
}
return Tool.responseTemplate(template, "index", Notice.html(LocalDateTime.now().format(Tool.yyyymmddhh))); }
当我在If(session.getCategoryCode()...会话变量处设置断点时,始终显示“com.sun.jdi.InvocationException:调用方法时,目标VM中出现异常。”
这是启动时出现异常错误
2021/06/22 09:35:13.916 WARNING [app.inject.MapperOfInternalServerError.toResponse] org.jboss.weld.contexts.ContextNotActiveException: WELD-001303: No active contexts for scope type jakarta.enterprise.context.SessionScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:647)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:89)
at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:164)
at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:87)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:131)
at app.inject.Session$Proxy$_$$_WeldClientProxy.getCategoryCode(Unknown Source)
at app.controller.Main.index(Main.java:90)
at app.controller.Main$Proxy$_$$_WeldClientProxy.index(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ObjectOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:192)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:475)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:397)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:255)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:831)
当我在org.jboss.weld.bean.proxy.ClientProxyProvider进行调试时
public <T> T getClientProxy(final Bean<T> bean, Type requestedType) {
// let's first try to use the proxy that implements all the bean types
T proxy = beanTypeClosureProxyPool.getCastValue(bean);
if (proxy == BEAN_NOT_PROXYABLE_MARKER) {
/*
* the bean may have a type that is not proxyable - this is not a problem as long as the unproxyable
* type is not in the type closure of the requested type
* https://issues.jboss.org/browse/WELD-1052
*/
proxy = requestedTypeClosureProxyPool.getCastValue(new RequestedTypeHolder(requestedType, bean));
if (proxy == BEAN_NOT_PROXYABLE_MARKER) {
throw Proxies.getUnproxyableTypeException(requestedType, services());
}
}
BeanLogger.LOG.lookedUpClientProxy(proxy.getClass(), bean);
return proxy;
}
在T proxy = beanTypeClosureProxyPool.getCastValue(bean);
时,它始终显示“com.sun.jdi "。调用异常:调用方法时,目标VM中出现异常。”
接下来,我创建Test.java,并仅在www.example.com中注入它Main.java
@SessionScoped
public class Test implements Serializable{
private static final long serialVersionUID = 1L;
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
Main.java
@Inject
private Test test;
@GET
@Path("index.html")
public Object index() {
if (session.getCategoryCode() != null) {
return Response.temporaryRedirect(URI.create("menu.html")).build();
}
return Tool.responseTemplate(template, "index", Notice.html(LocalDateTime.now().format(Tool.yyyymmddhh)));
}
因此,它显示了相同的错误。
=〉没有问题。只有会话作用域错误。
如何修复?
1条答案
按热度按时间bweufnob1#
问题:
jersey-cdi2-se
无法在Servlet环境中运作。更改为
jersey-cdi1x-servlet
=〉完成!!!!!!!!!!!!!参考:Tomcat 10:java.lang.NoClassDefFoundError:jakarta/企业/上下文/spi/上下文错误