0

spring 4.1.2 と Cassandra 2.1.2 をデータベースとして Web アプリケーションを構築しています。spring-data-cassandra の統合中に、bean creation exception が発生しました。私が間違っている場所を誰かが案内してくれますか? エラートレースは


org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.data.cassandra.core.CassandraOperations someapp.dao.role.JdbcSomeDao.cassandraOperations; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException. No qualifying bean of type [org.springframework.data.cassandra.core.CassandraOperations] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. 
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}        

私のソースコードは次
のとおりです。Webアプリケーションが初期化されるWeb初期化ファイル

public class WebInitConfig implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext rootContext = new           AnnotationConfigWebApplicationContext();
        rootContext.register(DispatcherConfig.class);
        servletContext.addListener(new ContextLoaderListener(rootContext));
        servletContext.setInitParameter("defaultHtmlEscape", "true");

        AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
           mvcContext.register(CassandraConfig.class);
        // The main Spring MVC servlet.
        ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", new DispatcherServlet(mvcContext));
                appServlet.setLoadOnStartup(1);
        Set<String> mappingConflicts = appServlet.addMapping("/");
        if (!mappingConflicts.isEmpty()) {
            for (String s : mappingConflicts) {
               System.out.println("Mapping conflict: " + s);
            }
            throw new IllegalStateException(
                 "'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14");
           }
        }

     }

Spring ディスパッチャー コードとビュー リゾルバーを含む DispatcherConfig ファイル。

@Configuration
@EnableWebMvc
@PropertySource("classpath:cassandra.properties")
@ComponentScan("randompackage.*")
public class DispatcherConfig extends WebMvcConfigurerAdapter {

     @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
     }

     @Bean
     public ViewResolver configureViewResolver() {
         InternalResourceViewResolver viewResolve = new InternalResourceViewResolver();
         viewResolve.setPrefix("/WEB-INF/jsp/");
         viewResolve.setSuffix(".jsp");

         return viewResolve;
     }

     @Override
     public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){
       configurer.enable();
     }
}

アプリケーションの起動時に webinitconfig.java に読み込まれる spring-data-cassandra 構成ファイル「CassandraConfig.java」

@Configuration
@PropertySource(value = { "classpath:cassandra.properties" })
@EnableCassandraRepositories(basePackages = { "someapp.dao" })
public class CassandraConfig {
/*  
      @Autowired
      private Environment env;
*/
      @Bean
      public CassandraClusterFactoryBean cluster() {

        CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
        cluster.setContactPoints("10.20.13.157");
        cluster.setPort(Integer.parseInt("9042"));

        return cluster;
      }

      @Bean
      public CassandraMappingContext mappingContext() {
        return new BasicCassandraMappingContext();
      }

      @Bean
      public CassandraConverter converter() {
        return new MappingCassandraConverter(mappingContext());
      }

      @Bean
      public CassandraSessionFactoryBean session() throws Exception {

        CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
        session.setCluster(cluster().getObject());
        session.setKeyspaceName("spring_data");
        session.setConverter(converter());
        session.setSchemaAction(SchemaAction.NONE);

        return session;
      }

      @Bean
      public CassandraOperations cassandraTemplate() throws Exception {
        return new CassandraTemplate(session().getObject());
      }


      @Bean(name="someManager")
      public SomeManager getSomeManager() throws Exception {
          return new someClassManager();
      }

      @Bean(name="someDao")
      public SomeDao getSomeDao() throws Exception {
          return new someDao();
      }

}

そして、それぞれのコントローラー、サービス、およびダオスがあります。

@Controller
public class SomeRegistrationController {

    @Autowired
    SomeManager someManager;

    @RequestMapping(value="registration.htm")
    public String registration() {
        someManager.Registration(new SomeDom());

        return "registration";

    }


}      

一部のマッピングのサービス クラス

@Service("someManager")
public class SomeClassManager implements SomeManager {

    @Autowired
    SomeDao someDao;


    @Override
    public void registration(SomeDom details) {
        someDao.registration(details);
    }

}

jdbc 相互作用のための Dao クラス

@Repository("someDao")
//@EnableAutoConfiguration
public class JDBCSomeDao implements SomeDao{

    @Autowired
    private CassandraOperations cassandraOperations;

    @Override
    public void Registration(SomeDom details) {
        System.out.println("JDBC");
        System.out.println(cassandraOperations.toString());     
    }
}
4

0 に答える 0