[ 
https://issues.apache.org/jira/browse/CXF-8176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17000601#comment-17000601
 ] 

Andriy Redko edited comment on CXF-8176 at 12/20/19 4:18 AM:
-------------------------------------------------------------

Hi [~richaosu] ,

Thank you for the sample project, the issue you are facing is clear now. So 
there are a few issues here, but first and foremost, this is not the issue with 
@Context but rather what you are trying to inject: HttpServletRequest. This 
class is (usually) not bundled with applications but provided by the servlet 
container and it seems like Weld just runs into issues with classloader when 
trying to load the generated proxy class for it.

There are couple of solutions to try out, probably the most acceptable in your 
case would be to bundle Weld with servlet container (for example, in case of 
Tomcat, add Weld dependencies into servlet container lib folder). If you really 
could avoid injecting Servlet API classes, things should work out of the box, 
without the need to bundle Weld dependencies with servlet container. Also 
please check the official Weld documentation: 
[https://docs.jboss.org/weld/reference/latest/en-US/html/environments.html].

Alternatively, you could try to replace @Context with @Inject @Any, it seems to 
work as expected:
{noformat}
@Inject @Any
private HttpServletRequest httpServletRequest; {noformat}
With respect to CXF, please use the CDI-aware servlet, no need for custom one:
{noformat}
<servlet-class>org.apache.cxf.cdi.CXFCdiServlet</servlet-class> {noformat}
Thank you.

Best Regards,

    Andriy Redko

 


was (Author: reta):
Hi [~richaosu] ,

Thank you for the sample project, the issue you are facing is clear now. So 
there are a few issues here, but first and foremost, this is not the issue with 
@Context but rather what you are trying to inject: HttpServletRequest. This 
class is (usually) not bundled with applications but provided by the servlet 
container and it seems like Weld just runs into issues with classloader when 
trying to load the generated proxy class for it.

There are couple of solutions to try out, probably the most acceptable in your 
case would be to bundle Weld with servlet container (for example, in case of 
Tomcat, add Weld dependencies into servlet container lib folder). If you really 
could avoid injecting Servlet API classes, things should work out of the box, 
without the need to bundle Weld dependencies with servlet container. Also 
please check the official Weld documentation: 
[https://docs.jboss.org/weld/reference/latest/en-US/html/environments.html].

With respect to CXF, please use the CDI-aware servlet, no need for custom one:
{noformat}
<servlet-class>org.apache.cxf.cdi.CXFCdiServlet</servlet-class> {noformat}
Thank you.

Best Regards,

    Andriy Redko

 

> Apache CXF @Context not class loading.
> --------------------------------------
>
>                 Key: CXF-8176
>                 URL: https://issues.apache.org/jira/browse/CXF-8176
>             Project: CXF
>          Issue Type: Bug
>          Components: Integration
>    Affects Versions: 3.2.2
>            Reporter: Richard O'Sullivan
>            Priority: Major
>         Attachments: CXF-ContentProducerBean-Fail-to-Load-Stacktrace.txt, 
> cxf-servlet-bug.tar.gz
>
>
> I have a WAR containing cxf-integration-cdi-3.2.1.jar that I deploy to Tomcat 
> V9, successfully. When I deploy a WAR containing 
> cxf-integration-cdi-3.2.7.jar, it fails to deploy because:
> {quote}org.jboss.weld.exceptions.WeldException: WELD-001524: Unable to load 
> proxy class for bean org.apache.cxf.cdi.ContextProducerBean@28c30f4d with 
> class class java.lang.Object using classloader 
> java.net.URLClassLoader@695caf9f
> {quote}
> My WAR includes the Weld v2.4.6 jars.
> Note: The ContextProducerBean class was introduced in CXF v3.2.2. 
> Others on the web, have reported a similar issue:
>  * 
> [https://stackoverflow.com/questions/56905194/class-not-found-in-war-but-is-available]
>  * [https://t.codebug.vip/questions-112783.htm]
>  I'm suspicious that there is no scope modifier on the constructor in the 
> ContextProducerBean class; thus, causing the scope to default to 'package 
> private' and become hidden from Tomcat's class loader. Also, the super class, 
> AbstractCXFBean<Object> does not declare a scope either. The fix might be to 
> add the 'public' modifier to both, just guessing.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to