John Smith
John Smith

Reputation: 1

Error injecting <Object>: Unable to create or inherit binding: No @Inject or default constructor found for <Object>

I'm new to gwt and gwtp. I'm trying to make a simple application that could connect and use EasyPost API. And when I try to run my code, it shows this error.

[INFO] --- gwt-maven-plugin:2.9.0:compile (default) @ EasyPostWebApp ---
[INFO] Compiling module easypost.EasyPostWebApp
[INFO]    Ignored 5 units with compilation errors in first pass.
[INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[ERROR] WARNING: An illegal reflective access operation has occurred
[ERROR] WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/C:/Users/Businessman/.m2/repository/com/google/inject/guice/3.0/guice-3.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
[ERROR] WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
[ERROR] WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
[ERROR] WARNING: All illegal access operations will be denied in a future release
[INFO]    Computing all possible rebind results for 'com.gwtplatform.mvp.client.DesktopGinjector'
[INFO]       Rebinding com.gwtplatform.mvp.client.DesktopGinjector
[INFO]          Invoking generator com.google.gwt.inject.rebind.GinjectorGenerator
[INFO]             [ERROR] Error injecting easypost.client.presenters.HomePresenter$MyProxy: Unable to create or inherit binding: No @Inject or default constructor found for easypost.client.presenters.HomePresenter$MyProxy
[INFO]   Path to required node:
[INFO] 
[INFO] easypost.client.presenters.HomePresenter$MyProxy [com.gwtplatform.mvp.client.gin.AbstractPresenterModule.bindPresenter(AbstractPresenterModule.java:121)]
[INFO] 
[INFO]             [ERROR] Error injecting easypost.client.views.HomeView$Binder: Unable to create or inherit binding: No @Inject or default constructor found for easypost.client.views.HomeView$Binder
[INFO]   Path to required node:
[INFO] 
[INFO] easypost.client.views.HomeView [com.gwtplatform.mvp.client.gin.AbstractPresenterModule.bindPresenter(AbstractPresenterModule.java:120)]
[INFO]  -> easypost.client.views.HomeView$Binder [@Inject constructor of easypost.client.views.HomeView]
[INFO] 
[INFO]    [ERROR] Errors in 'gen/com/gwtplatform/mvp/client/DesktopGinjectorProvider.java'
[INFO]       [ERROR] Line 8: Failed to resolve 'com.gwtplatform.mvp.client.DesktopGinjector' via deferred binding

Here are some source codes:

/client/EasyPostWebApp.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.9.0//EN"
        "http://gwtproject.org/doctype/2.9.0/gwt-module.dtd">
<module rename-to='easypostwebapp'>
  <inherits name='com.google.gwt.user.User'/>

  <inherits name='com.google.gwt.user.theme.clean.Clean'/>

  <inherits name = "com.google.gwt.uibinder.UiBinder"/>
  <inherits name="com.gwtplatform.mvp.MvpWithEntryPoint"/>

  <extend-configuration-property name="gin.ginjector.modules"
                                 value="easypost.client.views.ClientModule"/>

  <source path='client'/>
  <source path='shared'/>

  <set-configuration-property name="CssResource.enableGss" value="true"/>
  <set-configuration-property name="CssResource.gssDefaultInUiBinder" value="true"/>

  <!-- allow Super Dev Mode -->
  <add-linker name="xsiframe"/>
</module>

/client/views/HomeView.ui.xml

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:g='urn:import:com.google.gwt.user.client.ui'>
    <ui:style>...</ui:style>
    ...
    <g:HTMLPanel>
        <div class="{style.address-container}">
            <g:Button ui:field="createAddressButton">Create Address</g:Button>
            <div class="{style.address-box}">
                <g:HTML ui:field="serverResponse" />
            </div>
        </div>
    </g:HTMLPanel>

</ui:UiBinder>

/client/views/HomeView.java

public class HomeView extends ViewWithUiHandlers<HomeUiHandlers>
        implements HomePresenter.MyView {

    interface Binder extends UiBinder<HTMLPanel, HomeView> {}

    @UiField Button createAddressButton;
    @UiField HTML serverResponse;

    @Inject
    HomeView(Binder uiBinder) {
        initWidget(uiBinder.createAndBindUi( this ));

        createAddressButton.addClickHandler(clickEvent -> getUiHandlers().getServerResponse());
    }

    @Override
    public void setServerResponse(String serverResponse) {
        this.serverResponse.setHTML( serverResponse );
    }

/client/presenters/HomePresenter.java


public class HomePresenter extends Presenter<HomePresenter.MyView, HomePresenter.MyProxy>
            implements HomeHandlers {

    interface MyView extends View, HasUiHandlers<HomeUiHandlers> {
        void setServerResponse(String serverResponse);
    }

    @ProxyStandard
    @NameToken(NameTokens.HOME) // "/home"
    interface MyProxy extends Proxy<HomePresenter> {}

    private final EasyPostServiceAsync easyPostService;

    @Inject
    public HomePresenter(EventBus eventBus, HomePresenter.MyView view, HomePresenter.MyProxy proxy, EasyPostServiceAsync easyPostService) {
        super(eventBus, view, proxy, ApplicationPresenter.SLOT_MAIN);
        this.easyPostService = easyPostService;
        getView().setUiHandlers(this);
    }

    @Override
    public void getServerResponse() {
        getView().setServerResponse("Waiting for response...");

        easyPostService.helloFromServer(new AsyncCallback<>() {
            @Override
            public void onFailure(Throwable error) {
                getView().setServerResponse("An error occured: " + error.getLocalizedMessage());
            }

            @Override
            public void onSuccess(String response) {
                getView().setServerResponse(response);
            }
        });
    }

/client/gin/HomeModule.java

public class HomeModule extends AbstractPresenterModule {
    @Override
    protected void configure() {
        bindPresenter(HomePresenter.class, HomePresenter.MyView.class, HomeView.class,
                HomePresenter.MyProxy.class);
    }
}

/shared/services/EasyPostService

@RemoteServiceRelativePath("easyPost")
public interface EasyPostService extends RemoteService {
    String helloFromServer();
}

/shared/services/EasyPostServiceAsync

public interface EasyPostServiceAsync {
    void helloFromServer(AsyncCallback<String> callback);
}

/server/servlet/EasyPostServiceImpl.java

public class EasyPostServiceImpl extends RemoteServiceServlet implements EasyPostService {
    // sample method
    @Override
    public String helloFromServer() {
        return "Hello, I am from server!";
    }
}

Gin module:

public class ClientModule extends AbstractPresenterModule {

    @Override
    protected void configure() {
        install(new DefaultModule.Builder()
                .tokenFormatter(RouteTokenFormatter.class)
                .defaultPlace(NameTokens.HOME)
                .errorPlace(NameTokens.HOME)
                .unauthorizedPlace(NameTokens.HOME)
                .build()
        );
        install(new HomeModule());

        bind(ResourceLoader.class).asEagerSingleton();
    }
}

Am I doing this wrong or I'm just bad at this? Any help and tips are very appreciated. Thanks!

Edit: I made it simpler. The RPC works fine if I just use a normal custom entry point and calling the EasyPostServiceAsync directly with GWT.create(). But I want to achieve this with gwtp and codesplitting.

Upvotes: 0

Views: 558

Answers (0)

Related Questions