2016-10-15 17 views
0

私は現在のSpring 3.1.2プロジェクトでspring session mongoを使いたいのですが、失敗しました。 私のPOMの依存関係は、このようです:spring session with spring 3.1.2 not working

<dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>3.1.2.RELEASE</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.session</groupId> 
      <artifactId>spring-session</artifactId> 
      <version>1.3.0.M2</version> 
     </dependency> 
     <dependency> 
      <groupId>cglib</groupId> 
      <artifactId>cglib</artifactId> 
      <version>3.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.session</groupId> 
      <artifactId>spring-session-data-mongo</artifactId> 
      <version>1.2.2.RELEASE</version> 
      <type>pom</type> 
     </dependency> 

そして、私の構成は次のとおりです。

MVN tomcat7::私は使用してこのプロジェクトを開始した後

@Configuration 
@EnableMongoHttpSession 
public class HttpSessionConfig extends AbstractMongoConfiguration { 

    @Value("${mongo-url}") 
    String mongo_url; 

    @Bean 
    public JdkMongoSessionConverter jdkMongoSessionConverter() { 
      return new JdkMongoSessionConverter(); 
    } 


    @Bean 
    public Mongo mongo() throws UnknownHostException { 
     String url = mongo_url; 
     ArrayList<ServerAddress> addr = new ArrayList<ServerAddress>(); 
     for (String s : url.split(",")) { 
      addr.add(new ServerAddress(s)); 
     } 
     Mongo mongo = new Mongo(addr); 
     return mongo; 
    } 

    public @Bean MongoTemplate mongoTemplate() throws UnknownHostException { 
     return new MongoTemplate(mongo(), "mydb"); 
    } 



    @Override 
    protected String getDatabaseName() { 
     return "mydb"; 
    } 
} 

問題があるの実行を、

次のようなエラーが表示されます:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
java.lang.IllegalStateException: Cannot load configuration class: org.springframework.security.saml.web.HttpSessionConfig 
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:346) 
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:222) 
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686) 

spring-sessionはspring4以上でのみ動作しますか?この問題を解決するにはどうすればよいですか?

おかげ

更新

:この1に

<dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>3.2.14.RELEASE</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>3.2.14.RELEASE</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
       <groupId>org.springframework.session</groupId> 
       <artifactId>spring-session-data-mongo</artifactId> 
       <version>1.2.2.RELEASE</version> 
       <type>pom</type> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-mongodb</artifactId> 
      <exclusions> 
       <exclusion> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-logging</artifactId> 
       </exclusion> 
      </exclusions> 
      <version>1.2.2.RELEASE</version>  
     </dependency> 

と設定: 私は3.2.14.RELEASEにバージョンを変更し

@Configuration 
@EnableMongoHttpSession 
public class HttpSessionConfig extends AbstractMongoConfiguration { 

    //@Value("${mongo-url}") 
    String mongo_url; 

    @Bean 
    public JdkMongoSessionConverter jdkMongoSessionConverter() { 
      return new JdkMongoSessionConverter(); 
    } 


    @Bean 
    public Mongo mongo() throws UnknownHostException { 
     mongo_url = "127.0.0.1:27017";// "dev-ngcsc:27017,dev1-ngcsc:27017,dev2-ngcsc:27017"; 
     String url = mongo_url; 
     ArrayList<ServerAddress> addr = new ArrayList<ServerAddress>(); 
     for (String s : url.split(",")) { 
      addr.add(new ServerAddress(s)); 
     } 
     Mongo mongo = new Mongo(addr); 
     return mongo; 
    } 

    public @Bean MongoTemplate mongoTemplate() throws UnknownHostException { 
     return new MongoTemplate(mongo(), "ngcsc"); 
    } 



    @Override 
    protected String getDatabaseName() { 
     return "ngcsc"; 
    } 
} 

そして今、私はこのエラーを得ました:

Oct 15, 2016 8:15:55 AM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoSessionRepository' defined in class org.springframework.session.data.mongo.config.annotation.web.http.MongoHttpSessionConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.data.mongodb.core.MongoOperations]: : Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/security/saml/web/HttpSessionConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.mongodb.core.MongoTemplate org.springframework.security.saml.web.HttpSessionConfig.mongoTemplate() throws java.net.UnknownHostException] threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/objenesis/ObjenesisStd; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/security/saml/web/HttpSessionConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.mongodb.core.MongoTemplate org.springframework.security.saml.web.HttpSessionConfig.mongoTemplate() throws java.net.UnknownHostException] threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/objenesis/ObjenesisStd 

mongoの問題と思われますが、私はそれを改善できると思いますか?

私は4にバージョンをアップグレードしたが、別の問題は、次のように来る:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springSessionRepositoryFilter' defined in class path resource [org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.session.SessionRepository]: : No qualifying bean of type [org.springframework.session.SessionRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.session.SessionRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 

が、私は任意のBean定義を欠場しましたか?

+0

を参照してください? –

答えて

1

ドキュメントからの引用

If you are using other Spring libraries (not required), the minimum required version is Spring 3.2.14. While we re-run all unit tests against Spring 3.2.x, we recommend using the latest Spring 4.x version when possible.

spring-session documentation春のように古代のバージョンを使用する理由

+0

私はバージョンを3.2.14にアップデートしました。今ではmongoの問題が出てきます。ここでお手伝いできますか? – user3006967

+0

spring-boot-startter-data-mongoのどちらのバージョンのmongodbが使用されるのかわかりません。春のページで最も古いスプリングデータモンゴーバージョンは4.0.xですhttp://docs.spring.io/spring-data/data-mongo/docs/1.8.6.RELEASE/reference/html/#requirements –

+0

私は4にアップグレードして、いくつかのセッションの依存関係は、上のエラー、任意のアイデアを貼り付けたとして不足している? – user3006967