2
votes

I have a clojure class which I initialize using spring bean initialization.

My setter method is as follows

(defn -setCompanyName [currency] (println (str "company : " company)))

Bean initialization is as follows

<bean id="company" class="test.Company"
        p:companyName="orce"/>

I'm getting following error.

Invalid property 'companyName' of bean class [test.Company]: Bean property 'companyName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Does anyone knows the root cause for this issue.

Regards Isuru.

2

2 Answers

3
votes

There are several possible causes for this particular issue, so without all your code it is difficult to say what is failing.

Here is the code that works for me:

(ns test)

(gen-class
   :main false
   :name test.Company
   :methods [[setCompanyName [String] void]])

(defn -setCompanyName [this company] (println (str "company : " company)))

Notes:

  • you do not need any getter
  • the signature of the method is specified in the :methods vector.
  • your functions should have an additional "this" parameter
  • gen-class macro generates a class based on the parameters of the macro, so it does not look at the -setCompanyName function definition at all.

I find very useful the javap command to see what gen-class is generating:

javap.exe -classpath classes/ test.Company
public class test.Company extends java.lang.Object{
    public static {};
    public test.Company();
    public java.lang.String toString();
    public boolean equals(java.lang.Object);
    public java.lang.Object clone();
    public int hashCode();
    public void setCompanyName(java.lang.String);
}

I will also recommend you to look at the second example on http://clojuredocs.org/clojure_core/clojure.core/gen-class to see how to manage state.

0
votes

Don't you need another function parameter? The first acts as a 'this' pointer. I can't test this right now as I'm on my phone.