Note that there are some explanatory texts on larger screens.

plurals
  1. POAutowire a collection
    primarykey
    data
    text
    <p>Most of you probably will say that I should use google for this problem, since it's quite simple, but I can't find a truly correct solution that works.</p> <p>I have two session-scoped models: <code>Playlist</code> and <code>Track</code>. As you can guess, playlist contains a list of tracks:</p> <pre><code>@Component public class Playlist { String name; List&lt;Track&gt; tracklist; @Component public class Track { int duration; String artist; </code></pre> <p>I use <code>@Autowired</code> annotation in controllers to get the playlist. In the first controller I set the attributes of Playlist, in the second one I get them. Everything works fine with the <code>name</code> attribute of Playlist, but <code>tracklist</code> is null. I know that I must use something like <code>@Resource</code> or <code>@Qualifier</code>, but I don't understand how to make this annotations works. Simply writing</p> <pre><code>@Resource private List&lt;Track&gt; tracks; </code></pre> <p>does not seems to work. In my <code>servlet-context.xml</code> the two beans are declared like this:</p> <pre><code>&lt;bean id="track" class="com.foo.bar.models.Track" scope="session"&gt; &lt;aop:scoped-proxy/&gt; &lt;/bean&gt; &lt;bean id="playlist" class="com.foo.bar.models.Playlist" scope="session"&gt; &lt;aop:scoped-proxy/&gt; &lt;/bean&gt; </code></pre> <p>I've already look this <a href="https://stackoverflow.com/questions/6267138/spring-autowire-a-list">Spring autowire a list</a> but did not help me, since tracks are not declared via .xml but setted in a controller.</p>
    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.
 

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