2
我正在将我的应用从spring 3.x升级到spring 4.3。而不是xml配置我想要java配置(注释)。我无法使用注释进行配置。春季4.3什么是<task:annotation-driven>的注释4.3
<task:executor id="executor" pool-size="8-25" queue-capacity="100" />
<task:scheduler id="scheduler" pool-size="10" />
<context:component-scan annotation-config="true" base-package="com.jobs"/>
<task:annotation-driven executor="executor" scheduler="scheduler" />
何处以及如何使用注释来配置上述配置。 我想上面的XML配置适用于以下MyClassName.java
<bean id="mcn" class="com.jobs.MyClassName">
<property name="username" value="...."/>
<property name="authorities">
<list>
<value>....</value>
</list>
</property>
</bean>
我试着像下面的配置使用注释,但得到的异常:
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Properties 'authorities' and 'username' are required for bean 'myClassName'
MyClassName.java
@Component
public class MyClassName{
@Value("CronUser")
private String username;
//@Value("#{'ROLE_SYSTEM'.split(',')}")
@Value("#{'ROLE_SYSTEM'}")
private List<String> authorities;
@Required
public
void setUsername(final String aUsername)
{
username = aUsername;
}
@Required
public
void setAuthorities(final List<String> aAuthorities)
{
authorities = aAuthorities;
}
}
SprinQuartzJobConfig .java
package com.config;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@Configuration
@EnableAsync
@EnableScheduling
@ComponentScan({"com.jobs"})
public class SpringQuartzJobConfig {
@Bean
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(100);
executor.setMaxPoolSize(8-25);
executor.setQueueCapacity(100);
executor.initialize();
return executor;
}
@Bean
public Executor taskScheduler() {
// set properties if required
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(10);
return scheduler;
}
}
以上xml配置的注释是什么?
指定,否则所有的 –
@Autowired
字段默认强制移除感谢您响应。但是,我需要为看到编辑 - “@ ComponenetScan”需要添加配置类,它支持多包扫描以及 –
意味着我需要创建单独的配置类作为DemoApplication类? –