简体   繁体   中英

Working Java JNDI Lookup from EJB to WAR causes tons of log errors

I am using a lookup that looks like this:

package com.program.my.api;

import com.program.my.companies.CompanyManager; // Remote Interface in EJB

public class Services
{
    public static CompanyManager getCompanyManager() { return getService(CompanyManager.class); } 

    public static <T> T getService(Class<T> c)
    {
        try {
            InitialContext ctx = new InitialContext(System.getProperties());

            T result = (T) ctx.lookup(c.getName());

            return result;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

// Usage
@Stateless
@Path("/companies")
public class CompanyService
{
    @GET
    @Path("getCompanyOverview")
    @Produces(MediaType.APPLICATION_JSON)
    public CompanyOverviewTO getCompanyOverview(@QueryParam("id") int id)
    {
        return Services.getCompanyManager().getCompanyOverview(id);
    }
}

The lookup works! Ok, that's fine, but in the logs I get tons of errors that look like this:

javax.naming.NameNotFoundException: No object bound to name java:app/my-ejb-2.0/CompanyService!com.program.my.api.CompanyService

This doesn't make any sense. Mostly because the classname isn't in my api war, it's in the EJB, but also bc the code works. It just throws logs this error before it does.

It's needlessly filling up my logs.

Any ideas?

So it turns out that packaging multiple WAR's into a single EAR was causing a lot of problems. Even though none of the url paths were crossing, Glassfish still didn't like it.

Merged everything into a single ear and all my problems disappeared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM