Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:02:38+00:00 2026-06-05T15:02:38+00:00

I have @LocalBean s and JAX-RS resources in different packages in a single ear.

  • 0

I have @LocalBeans and JAX-RS resources in different packages in a single ear.

And I also have a ServletFilter filtering before those resources.

I found that @EJB works for the ServletFilter but not for those resources.

@Stateless
@LocalBean
class MyBean { // in ejb jar
}

@WebFilter(urlPatterns = {"/*"})
class MyFilter implements Filter { // in the same war
    @EJB MyBean myBean; // not null
}

@ApplicationPath("/")
class MyApplication extends Application { // in the same war
}

@Path("/my")
class MyResource { // in the same war
    @EJB MyBean myBean; // null
}

No logs special, just an NPE in MyResource’s method.
Can anybody help me?

UPDATE ———————————————–

Making those resource classes as @Stateless do works.

But I just curious that those ejb-jar and web-war are assembled into a single ear.

And then the web-war is a web component, isn’t it?

UPDATE2 ——————————————————

Oh, I’m sorry. There is also MyApplication that makes MyResource as a JAX-RS resource.

When I deploy the ear GF detect it as an ‘Enterprise Application’.

UPDATE3 —————————————————————

Here comes my application.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
  <display-name>sngp-v0-ear</display-name>
  <module> <!-- EJBs are here -->
    <ejb>sngp-v0-beans-1.0-alpha-1-SNAPSHOT.jar</ejb>
  </module>
  <module>
    <web> <!-- JAX-RS are here -->
      <web-uri>sngp-v0-mobile-resources-1.0-alpha-1-SNAPSHOT.war</web-uri>
      <context-root>/sngp-v0-mobile-resources</context-root>
   </web>
  </module>
  <library-directory>lib</library-directory>
</application>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:02:40+00:00Added an answer on June 5, 2026 at 3:02 pm

    MyResource class isn’t either a web component or an enterprise bean, but you are trying to inject an EJB into it. EJB injection is guaranteed to work only when the client is either a web component or another enterprise bean.

    Try making MyResource @Stateless.

    Have a look at this Java EE 6 tutorial regarding EJB injection. If you are using NetBeans, I have also found useful using the built-in wizard for creating RESTFul web services. Check out this link in case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a no-interface ejb deployed in an ear (MyEar.ear) @Stateless @LocalBean public class
I have an EJB Project with a @Singleton EJB defined as: @LocalBean @Singleton @Startup
I have a @Stateless @LocalBean which looks like this @LocalBean @Stateless class TokenBean {
Have found maven to use hard for simple things like jar-signing ..May be I
Have an app that can use tts to read text messages. It can also
Suppose I have a stateless bean: @Stateless(name = fooBean) @LocalBean public class Foo {
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have done quite a bit of searching for a guide (of any substance) for
Have deployed numerous report parts which reference the same view however one of them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.