Asif
Asif

Reputation: 397

Parameter 0 of constructor 'java.lang.String' that could not be found

My project developed by Grails 4, actually I am upgrading from Grails 2 to Grails 4. Can you suggest me a solution how can I solve it? Thanks

Error:

 Parameter 0 of constructor in com.bv.session.AjaxAwareAuthenticationEntryPoint required a bean of type
     'java.lang.String' that could not be found. 

recourse.groovy:

beans = {

    authenticationEntryPoint(com.bv.session.AjaxAwareAuthenticationEntryPoint) {
        loginFormUrl = '/login/auth' 
        grailsUrlMappingsHolder = ref('grailsUrlMappingsHolder')
        portMapper = ref('portMapper')
        portResolver = ref('portResolver')
    }

} 

Class:

public class AjaxAwareAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {

    private UrlMappingsHolder proxyBean;
    public AjaxAwareAuthenticationEntryPoint(String loginFormUrl) {
        super(loginFormUrl);
    }

    @Override
    protected String determineUrlToUseForThisRequest(final HttpServletRequest request,
                                                     final HttpServletResponse response, final AuthenticationException e){

        String controllerName = (String)proxyBean.match(request.getServletPath()).getParameters().get("controller");

        String ajaxHeader = ((HttpServletRequest) request).getHeader("X-Requested-With");

        if ("XMLHttpRequest".equals(ajaxHeader)){
            return "/login/auth?session_expired_ajax=true";

        }

        if(request.getSession(false).isNew() || "index.gsp".equals(controllerName)) {
            return "/login/auth";
        }else{
            return "/login/auth?session_expired=true";
        }
    }

    public void setGrailsUrlMappingsHolder(UrlMappingsHolder proxyBean) {
        this.proxyBean = proxyBean;
    }
}

Tools:

Upvotes: 0

Views: 248

Answers (1)

cfrick
cfrick

Reputation: 37008

From the docs:

19.3 The BeanBuilder DSL Explained

Using Constructor Arguments

Constructor arguments can be defined using parameters to each bean-defining method. Put them after the first argument (the Class):

bb.beans {
    exampleBean(MyExampleBean, "firstArgument", 2) {
        someProperty = [1, 2, 3]
    }
}

This configuration corresponds to a MyExampleBean with a constructor that looks like this:

MyExampleBean(String foo, int bar) {
   ...
}

Upvotes: 1

Related Questions