2017-06-11 11 views
0

私は小さな問題を抱えています。私はJavaベースの設定をXMLベースの設定と組み合わせようとしています。私は小さな問題があります。私はそれをスキャンしようとしています。@ImportResource注釈ですが、開始時に春はbeanCreationExceptionにつながる設定ファイルを読み込めず、フィールドをオートワイヤできませんでした。ここSpringルートコンテキストが@ImportResource経由でロードされない

私のファイルは

RootConfig.javaある

@Configuration 
    @ImportResource({ "classpath*: applicationContext.xml" }) 
    public class RootContextConfiguration { 
     public RootContextConfiguration() { 
      super(); 
     } 
    } 

WebAppInitilizer.java

public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 

     @Override 
     protected Class<?>[] getRootConfigClasses() { 
      return new Class[] { RootContextConfiguration.class, SecurityContextConfiguration.class }; 
     } 

     @Override 
     protected Class<?>[] getServletConfigClasses() { 
      return new Class[] { ServletContextConfiguration.class }; 
     } 

     @Override 
     protected String[] getServletMappings() { 
      return new String[] { "/" }; 
     } 
    } 

org.springframework.beans.factory.BeanCreationException: ができませんでしたautowireフィールド:priv ate ma.xxx.net.repos.UserRepository ma.xxx.net.service.impl.UserServiceImpl.userRepository;

見つからなかったために注入できなかったと思います。

これはスプリングデータ管理のリポジトリです。

@Repository 
    public interface UserRepository extends JpaRepository<User, Long>{ 

    } 

これは、あなたが

@Service("userService") 
    public class UserServiceImpl implements IUserService { 

     @Autowired 
     private UserRepository userRepository; 

     @Override 
     public User getUser() { 
      return userRepository.findOne(1L); 
     } 
    } 

を求めたものですが皆さんはこれで私を助けることができます願っています。

+0

はあなたの設定を表示することができます存在する場合、パッケージには、あなたのコンフィグ@EnableJpaRepositoriesとポイントに追加する必要がありますか?あなたは、サービスへのリポジトリBeanをautowired方法も – xyz

+0

推定しないでください。ルートコンテキストに本当にシンプルなBeanを追加し、System.outに出力して、ルートコンテキストがBeanをインスタンス化するかどうかを確認します。 –

+0

applicaitonContext.xmlとスタックトレースを表示して、例外に関する詳細情報を取得できますか? –

答えて

0

は、リポジトリが

@EnableJpaRepositories(basePackages = "your.repository.package") 
関連する問題