2016-03-04 55 views
0

我無法讓自動佈線註釋在我的彈簧啓動應用程序中工作。自動佈線導致彈簧啓動應用程序出現異常

是我收到的錯誤是「無法自動裝配領域。類型沒有合格豆」

我覈實,從斷控制器的代碼不是POJO和春天有註釋。

我也無法在包外運行我的主要方法。有什麼建議麼?

package com.xxx.controller; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.builder.SpringApplicationBuilder; 
import org.springframework.boot.context.web.SpringBootServletInitializer; 

@SpringBootApplication 
public class SampleWebJspApplication extends SpringBootServletInitializer { 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
     return application.sources(SampleWebJspApplication.class); 
    } 

    public static void main(String[] args) throws Exception { 
     SpringApplication.run(SampleWebJspApplication.class, args); 
    } 

} 

UserService類

package com.xxx.service; 

    import java.util.List; 

    import org.springframework.beans.factory.annotation.Autowired; 
    import org.springframework.stereotype.Service; 

    import com.xxx.entity.User; 
    import com.xxx.repository.UserRepository; 

    @Service 
    public class UserService { 

     @Autowired 
     private UserRepository userRepository; 

     public List<User> findAll() { 
      return userRepository.findAll(); 
     } 

    } 

UserRepository類

package com.xxx.repository; 

import org.springframework.data.jpa.repository.JpaRepository; 

import com.xxx.entity.User; 

public interface UserRepository extends JpaRepository<User, Integer> { 

} 

回答

1

有可能是這兩個可能的原因:

  • 組件包不包括在@ComponentScan包。
  • 軟件包中不包含軟件包的存儲庫。
+0

我刪除了SpringBootApplication註釋,並用ComponentScan和EnableJpaRepositories替換它。然後,我添加必要的basePackages。這並沒有解決問題。還有其他建議嗎? – Albert

相關問題