2016-10-15 2 views
0

Я хочу использовать весеннюю сессию mongo с моей текущей пружиной 3.1.2, но не удалось. Моя POM зависимость заключается в следующем:используя весеннюю сессию с пружиной 3.1.2 не работает

<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> 

И моя конфигурация:

@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"; 
    } 
} 

Проблема заключается в том, когда я начать этот проект с помощью:

МВН tomcat7: бег,

У меня возникла ошибка:

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) 

Весна-сессия работает только с пружиной4 и выше? Как я могу исправить эту проблему?

Благодаря

Обновлено: Я изменил версию 3.2.14.RELEASE:

<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> 

и конфигурация этого:

@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 

Считается проблемой манго, любая идея, что я могу ее улучшить?

Я обновил версию до 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: {} 

Я не пропустить какое-либо определение фасоли?

+0

Зачем использовать такую ​​древнюю версию Spring? –

ответ

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, теперь идет вопрос о манго, вы можете помочь здесь? – user3006967

+0

Я не уверен, какая версия весны mongodb будет использована spring-boot-starter-data-mongo. Самая старая версия Spring-data-mongo на странице весны говорит, что 4.0.x см. Http://docs.spring.io/spring-data/data-mongo/docs/1.8.6.RELEASE/reference/html/#requirements –

+0

Я обновил до 4, и некоторая зависимость от сеанса отсутствует, так как выше вставлена ​​ошибка, любая идея? – user3006967

Смежные вопросы