1

What exactly would be an equivalent manual configuration to mvc:annotation-driven in spring mvc? Because my webapp implements RequestMappingHandlerMapping, I cannot use mvc:annotation-driven but have to configure this myself.

Specifically I'm wondering what configuration has to be included in order for the @Async annotation to work. I am not sure if it does atm. I'm starting a background task at startup which is supposed to run as long as the webapp is running and it seems to me that the whole server waits for this (never-ending) method to finish. The @Async-Method is in a worker-service which gets called by another service on @PostConstruct.

Here are the two classes:

@Service
public class ModuleDirectoryWatcher{
    @Autowired
    ModuleDirectoryWatcherWorker worker;

    @PostConstruct
    public void startWatching() {
        worker.startWatching();
    }
}

@Service
public class ModuleDirectoryWatcherWorker {
    @Async
    public void startWatching() {
        createPluginDir();
        initializeClassloader();
        initializeWatcher();
        watch();
    }
}

The relevant part of my applicationContext.xml looks like this so far:

<bean name="handlerAdapter"
 class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">    
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"</bean>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
        </list>
    </property>
</bean>

<bean name="handlerMapping"
 class="com.coderunner.caliope.module.api.impl.ModuleHandlerMapping">
</bean>
nanoquack
  • 949
  • 2
  • 9
  • 26
  • 1
    Do you mean what configuration you need to add to make `@Async` work? – Sotirios Delimanolis Aug 15 '13 at 20:31
  • Yes that's exactly what I meant. First I didnt realize that there is a task:annotation-driven and a mvc:annotation driven. Minutes later I discovered what was missing, see below... – nanoquack Aug 16 '13 at 07:47

1 Answers1

1

Now I feel silly... In order to work, @Async and @Scheduled need

<task:annotation-driven executor="myExecutor" scheduler="myScheduler" />
<task:executor id="myExecutor" pool-size="5" />
<task:scheduler id="myScheduler" pool-size="10" />

even if you don't use

Maybe it helps someone out there

nanoquack
  • 949
  • 2
  • 9
  • 26