[英]spring boot 1.2.5 @Configuration @Autowired annotation null?
[英]Spring @Configuration annotation @Autowired service is null
我正在使用Spring Configuration和Jersey配置。
這是我的彈簧配置:
@Component
@Configuration
@EnableScheduling
@EnableAspectJAutoProxy
@EnableTransactionManagement
@ComponentScan(basePackages = { "my.packages" })
public class SpringConfig {
private static final String MESSAGE_SOURCE_BASE_NAME = "i18n/messages";
@Profile(Profiles.APPLICATION)
@Configuration
@PropertySource("classpath:application.properties")
static class ApplicationProperties {
}
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder(11);
}
@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}
@Bean
MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(MESSAGE_SOURCE_BASE_NAME);
messageSource.setUseCodeAsDefaultMessage(true);
return messageSource;
}
}
這是我的Service類和接口:
public interface DAOService {
User register(User user)
}
@Service
public class DAOServiceImpl implements DAOService {
@Override
User register(User user){
return null;
}
}
這是我的球衣資源:
在ResourceSecurityService類內部,我想對DAOService類使用@Autowire,但出現空指針異常,daoService始終為空。
@Component
@Path("/security")
@Produces({ MediaType.APPLICATION_JSON })
public class ResourceDAOService {
@Autowired
private DAOService daoService ; //<--- here daoService is null;
@POST
@Path("/register")
@Consumes({ MediaType.APPLICATION_JSON })
@Transactional
public Response register(User user, @Context HttpServletRequest request,
@Context HttpServletResponse response) throws AppException {
return Response.status(Response.Status.CREATED).entity(securityService.register(user)).build();
}
我正在使用具有以下依賴項的春季版本4.3.8.RELEASE:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
如果提供到項目的鏈接可能會更好。 根據信息,我看到:
jersey-spring4
依賴性 我建議您將Spring Boot與自動配置一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.