Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable and disable implicit scanning per JAR. #20483

Closed
glassfishrobot opened this issue May 7, 2013 · 13 comments
Closed

Enable and disable implicit scanning per JAR. #20483

glassfishrobot opened this issue May 7, 2013 · 13 comments

Comments

@glassfishrobot
Copy link

beans.xml cannot be added to a third-party JAR. Disabling implicit CDI is one option but but it works at the application level.

This will not work when different third-party JARs make different assumptions about implicit beans. So it would be helpful if GlassFish (or Weld) offered a way to enable or disable implicit scanning per JAR.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Reported by @jjsnyder

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
@jjsnyder said:
According to 12.1 of CDI spec:
"For compatibility with Contexts and Dependency 1.0, products must contain an option to cause an archive to be ignored by the container when no beans.xml is present."

We are probably a little light in our implementation of this as we only allow entire apps to be enabled/disabled for implicit scanning.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
aaronjwhiteside said:
Related to #20579. It would be good if this was part of the final 4.0.0 release. Perhaps something in glassfish-web.xml?

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
aaronjwhiteside said:
http://docs.jboss.org/weld/reference/latest/en-US/html/configure.html

This doesn't work as far as I can tell.

Maybe fixing the WELD integration so that this works is the solution?

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
aaronjwhiteside said:
I can add a beans.xml as per the CDI 1.1 spec, but that does not appear to work either.

CDI 1.1 Spec, Section 12.1
bean-discovery-mode="none" should disable an archives contents from being considered by CDI.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
@pzampino said:
The cited beans.xml addition should work. If it is being applied correctly, and Glassfish is not honoring it, then that's a bug. Can you provide an application to reproduce this behavior?

Additionally, there is a new deployment property that will disable support for implicit bean archives at the application level. (asadmin deploy --property implicitCdiEnabled=false )

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Marked as fixed on Wednesday, June 12th 2013, 9:45:25 am

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
everett_toews said:
How exactly was this resolved?

bean-discovery-mode="none" does work for me but this issue is for disabling implicit scanning per JAR.

To disable scanning per JAR I tried the following beans.xml and it didn't work for me. I continue to get WELD errors.

<beans xmlns="http://java.sun.com/xml/ns/javaee" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:weld="http://jboss.org/schema/weld/beans" 
       xsi:schemaLocation="
          http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
          http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">
    <weld:scan>
        <weld:exclude name="org.jclouds.**" />
    </weld:scan>
</beans>

Should this beans.xml work with Glassfish 4.1?

Can someone provide an example of a beans.xml file that excludes per JAR that does work?

Thanks.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
everett_toews said:
Just to be clear, I put that beans.xml file in the web app WEB-INF dir.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
reipince said:
This is not fixed.

I have jars that contain unimplemented interfaces, and therefore when they're scanned for CDI, they cause an error and I can't deploy my app.

I tried explicitly using an exclude rule in my beans.xml but it seems to take no effect.

My options are:

  • disable implicit cdi at the application level
  • disable cdi scanning at the beans.xml level (using "none" as the bean-discovery-mode).

Both of these options are bad since they require me to explicitly annotate everything that's being injected right now, which is quite a lot of stuff...

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
@jjsnyder said:
You have the following choices:

  1. Disable implicit CDI for all apps. Use this command:
    asadmin set configs.config.server-config.cdi-service.enable-implicit-cdi=false

  2. Disable CDI for each jar you do not want to participate in CDI. To do this you must add a beans.xml to each individual jar with the following content:


Note that for option 2 you must do this for each individual jar. The beans.xml in WEB-INF only applies to the classes in WEB-INF/classes.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
This issue was imported from java.net JIRA GLASSFISH-20483

@glassfishrobot
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant