當我嘗試查找從另一個模塊一個EJB,JBoss會返回此異常:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy125 cannot be cast to com.foo.spring.logging.UserCategoryLogService
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:822)
javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:722)
它看起來像目前爲止查找工作正常,但我根本無法投射對象。 我的項目是一個Spring-MVC項目。我正在連接的後端接收UserCategoryLogService,它是一個簡單的Java-EE項目。
我嘗試了不同的方法來查找和投射。通常我走這條路:
try {
UserCategoryLogService logService = (UserCategoryLogService) new InitialContext.lookup("java:jboss/exported/backend/UserCategoryLogServiceImpl!logging.UserCategoryLogService");
logService.logLogin(username);
} catch (NamingException e) {
e.printStackTrace();
}
,通常這是工作,當我在我的後端項目做本地EJB的查找。 我也嘗試創建一個屬性並在創建新的上下文時使用它。它將返回相同的錯誤。
我將UserCategoryLogService接口添加到了我的spring-config.xml中,但它無濟於事。
春天我沒有做關於JNDI的額外配置。 我試圖查找@Local和@Remote,兩者都會返回相同的castingException。
我使用Wildfly 8.1.0
你有任何想法如何處理代理對象?那麼爲什麼ejb-lookup可以和我的java-ee後端一起工作,而不是用我的spring-mvc項目呢?
接口春天項目:
import javax.ejb.Remote;
@Remote
public interface UserCategoryLogService {
void logUserCatCall(String userId, Integer categoryId);
void logLogin(String userId);
}
乾杯
編輯二零一四年九月二十七日:
我發現這個問題: Injecting EJB 3 into Spring Bean
於是,我就自動裝配豆和我得到了同樣的錯誤:
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'java:jboss/exported/backend/UserCategoryLogServiceImpl!logging.UserCategoryLogService' must be of type [com.frontend.spring.logging.UserCategoryLogService], but was actually of type [com.sun.proxy.$Proxy105]
EDIT2:
@Bean
UserCategoryLogService getUserCatLogService() {
UserCategoryLogService ucLog = null;
JndiTemplate template = new JndiTemplate();
try {
ucLog = (UserCategoryLogService) template.lookup("java:jboss/exported/backend/UserCategoryLogServiceImpl!logging.UserCategoryLogService");
} catch (NamingException e) {
e.printStackTrace();
}
return ucLog;
}
是行不通的兩種:
threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy125 cannot be cast to com.recc.frontend.logging.UserCategoryLogService
這是否被部署爲單耳應用? – maress 2014-09-25 11:14:47
2個項目,都部署爲.war文件 – Goot 2014-09-25 12:16:29
此問題現在有一個賞金 – Goot 2014-09-29 12:43:17