We have to share our code base with a partner for developing, but we don't want to reveal the implementation of some services.
Say we have an interface FooService and its implementation FooServiceImpl.
public interface FooService
{
void doSomething();
}
@Service
public class FooServiceImpl implements FooService
{
@Override
public String doSomething();
{
...
}
}
Many other classes autowire this service in and call doSomething(). For example:
@Service
public class BarServiceImpl implements BarService
{
@Autowired
private FooService fooService;
@Override
public String validate();
{
fooService.doSomething();
...
}
}
If I just delete FooServiceImpl, of course a NoSuchBeanException will be thrown while starting. If I use @Autowired(required = false) everywhere that FooService is autowired, a NullPointerException will be thrown at runtime whenever doSomething() gets called.
Besides the removal of each method body in FooServiceImpl manually, is there any other way to work this around?
Any help is appreciated.
No.
You are trying to create instance for an Interface which is not possible in Java.