Java Lambda注入服务+;刀

Java Lambda注入服务+;刀,java,spring,spring-boot,dependency-injection,aws-lambda,Java,Spring,Spring Boot,Dependency Injection,Aws Lambda,我有一个AmazonLambda(springboot),它已经部署好,运行良好 我通过以下方式从外部项目(依赖项添加到pom)注入服务: @Bean public SomeExternalService someExternalService() { return new SomeExternalService; } 我必须这样做,因为当上传到亚马逊时,@Autowired不起作用 现在,从另一个springboot项目(不是lambda)中,我得到了这个使用DAO的服务 服务 @S

我有一个AmazonLambda(springboot),它已经部署好,运行良好

我通过以下方式从外部项目(依赖项添加到pom)注入服务:

@Bean
public SomeExternalService someExternalService() {
    return new SomeExternalService;
}
我必须这样做,因为当上传到亚马逊时,@Autowired不起作用

现在,从另一个springboot项目(不是lambda)中,我得到了这个使用DAO的服务

服务

@Service
public class StateService  {

@Autowired
private StateRepository repository;

/**
 * Find all {@code State}
 */
public void findSomething(String thing) {
    return repository.findSomething("thing");
}
.....
存储库

@EnableScan
public interface StateRepository extends PagingAndSortingRepository<State, String> {
    List<State> findSomething(String thing);

我不能对
StateRepository

执行相同的操作,StateRepository类必须具有@Component注释,或者将其作为@Bean添加到@Configuration类中

@Configuration
@ComponentScan("com.company")
public class ConfigClass {
   // your @Bean's
   @Bean
   public StateRepository stateRepository() {
       return new StateRepository();
   }
   // now can @Autowired
}

如果您使用
@Autowired
,则表示Spring定义了您要注入的bean。在您的情况下,我不确定Spring是否知道
StateRepository
,并且该存储库不在上下文中。您是否尝试使用
@Bean
创建存储库?不需要,它已经有@Service,注入服务不是问题。注入存储库是非常困难的。编辑,我现在正在尝试我的意思是StateRepository或创建StateRepository的bean不,这没有帮助。当部署在AmazonYou上时,它仍然找不到bean存储库。您有
org.springframework.beans.factory.NoSuchBeanDefinitionException
,它只说没有使用注释或xml配置的bean定义。如果您有添加它的xml配置文件。如果使用
@Component
注释,则不再需要它。
@Configuration
@ComponentScan("com.company")
public class ConfigClass {
   // your @Bean's
   @Bean
   public StateRepository stateRepository() {
       return new StateRepository();
   }
   // now can @Autowired
}