Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, you have two problems:</p> <ul> <li><p>Property should be mutable, i.e. <code>var</code> rather than <code>val</code></p></li> <li><p>All methods of Scala <code>object</code> are <code>static</code>, whereas Spring expects instance methods. Actually Scala creates a class with instance methods named <code>UserRest$</code> behind the scene, and you need to make its singleton instance <code>UserRest$.MODULE$</code> available to Spring.<br> Spring can apply configuration to preexisting singleton instances, but they should be returned by a method, whereas <code>UserRest$.MODULE$</code> is a field. Thus, you need to create a method to return it.</p></li> </ul> <p>So, something like this should work:</p> <pre><code>object UserRest extends RestHelper { @BeanProperty var userRepository: UserRepository = null; def getInstance() = this ... } </code></pre> <p>.</p> <pre><code>&lt;bean id="userRest" class="com.abc.rest.UserRest" factory-method = "getInstance"&gt; &lt;property name="userRepository" ref="userRepository"/&gt; &lt;/bean&gt; </code></pre> <p>You can replace <code>&lt;property&gt;</code> with <code>@Autowired</code>, but cannot replace manual bean declaration with <code>@Service</code> due to problems with singleton instance described above.</p> <p><strong>See also:</strong></p> <ul> <li><a href="https://stackoverflow.com/questions/7819866/what-is-the-java-equivalent-of-a-scala-object">What is the Java equivalent of a Scala object?</a></li> <li><a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-class-static-factory-method" rel="nofollow noreferrer">3.3.2.2 Instantiation with a static factory method</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload