Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating repository [DATACOUCH-604] #912

Closed
spring-projects-issues opened this issue Aug 19, 2020 · 3 comments
Closed

Error creating repository [DATACOUCH-604] #912

spring-projects-issues opened this issue Aug 19, 2020 · 3 comments
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Aug 19, 2020

Martin opened DATACOUCH-604 and commented

Repository with entity that extends from org.springframework.security.oauth2.common.DefaultOAuth2AccessToken cannot be created since 4.0.2.
 

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'OAuth2AccessTokenRepository' defined in OAuth2AccessTokenRepository defined in @EnableCouchbaseRepositories declared on RepositoryConfig: Invocation of init method failed; nested exception is java.lang.NullPointerException
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
	... 20 common frames omitted
Caused by: java.lang.NullPointerException: null
	at org.springframework.data.couchbase.core.mapping.BasicCouchbasePersistentProperty.getFieldName(BasicCouchbasePersistentProperty.java:78)
	at org.springframework.data.couchbase.core.mapping.BasicCouchbasePersistentProperty.isIdProperty(BasicCouchbasePersistentProperty.java:103)
	at org.springframework.data.couchbase.core.mapping.BasicCouchbasePersistentEntity.returnPropertyIfBetterIdPropertyCandidateOrNull(BasicCouchbasePersistentEntity.java:72)
	at org.springframework.data.couchbase.core.mapping.BasicCouchbasePersistentEntity.returnPropertyIfBetterIdPropertyCandidateOrNull(BasicCouchbasePersistentEntity.java:39)
	at org.springframework.data.mapping.model.BasicPersistentEntity.addPersistentProperty(BasicPersistentEntity.java:218)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:552)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
	at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1675)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.addPropertiesForRemainingDescriptors(AbstractMappingContext.java:537)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:390)
	at java.base/java.util.Collections$SingletonSet.forEach(Collections.java:4797)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:562)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:520)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:705)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:389)
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:263)
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:206)
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:90)
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$4(RepositoryFactoryBeanSupport.java:295)
	at java.base/java.util.Optional.ifPresent(Optional.java:183)
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:295)
	at org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactoryBean.afterPropertiesSet(CouchbaseRepositoryFactoryBean.java:89)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
	at org.springframework.beans.fac

 Repository example: 

public interface OAuth2AccessTokenRepository extends CouchbaseRepository<CouchbaseOAuth2AccessToken, String> {

    List<CouchbaseOAuth2AccessToken> findByUserName(String userName);

    List<CouchbaseOAuth2AccessToken> findByClientId(String clientId);

    List<CouchbaseOAuth2AccessToken> findByClientIdAndUserName(String clientId, String userName);

}

  Entity CouchbaseOAuth2AccessToken
 

@Document(expiry = 30 * 24 * 60 * 60)
public class CouchbaseOAuth2AccessToken extends DefaultOAuth2AccessToken {

    private static final long serialVersionUID = 6537949925775752989L;

    @Id
    private String tokenId;

    @Field
    private String authentication;

    @Field
    private String authenticationKey;

    @Field
    private String clientId;

    @Field
    private String userName;

    private CouchbaseOAuth2AccessToken() {
        this((String) null);
    }

    public CouchbaseOAuth2AccessToken(OAuth2AccessToken accessToken) {
        super(accessToken);
        this.tokenId = accessToken.getValue();
    }

    public CouchbaseOAuth2AccessToken(String value) {
        super(value);
        this.tokenId = value;
    }

    // getters and setters omitted for brevity
}

 DefaultOAuth2AccessToken

 


Affects: 4.0.3 (Neumann SR3)

Referenced from: pull request #260

Backported to: 4.0.5 (Neumann SR5)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 19, 2020

Michael Reiche commented

Can you post your pom?
With 2.5.0,  I get 

Error:(9, 8) java: no suitable constructor found for DefaultOAuth2AccessToken(no arguments)
constructor org.springframework.security.oauth2.common.DefaultOAuth2AccessToken.DefaultOAuth2AccessToken(java.lang.String) is not applicable
(actual and formal argument lists differ in length)
constructor org.springframework.security.oauth2.common.DefaultOAuth2AccessToken.DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) is not applicable
(actual and formal argument lists differ in length)

<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.5.0.RELEASE</version>

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 20, 2020

Martin commented

parent build.gradle (I removed non-spring dependencies)

plugins {
    id 'org.springframework.boot' version '2.3.3.RELEASE' apply false
}
allprojects {    
    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'io.spring.dependency-management'

    sourceCompatibility = '11'
    targetCompatibility = '11'

    dependencyManagement {
        dependencies {
            dependency "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.3.3.RELEASE"
        }
    }
}

server module build.gradle

plugins {
    id "net.ltgt.apt" version "0.21"
    id "net.ltgt.apt-eclipse" version "0.21"
    id "net.ltgt.apt-idea" version "0.21"
    id 'com.palantir.docker' version '0.22.1'
}

apply plugin: 'org.springframework.boot'

springBoot {
    buildInfo()
}

configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
}

compileJava.dependsOn(processResources)

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation "org.springframework.boot:spring-boot-starter-cache"
    implementation "org.springframework.boot:spring-boot-starter-security"
    implementation "org.springframework.boot:spring-boot-starter-validation"
    implementation "org.springframework.boot:spring-boot-starter-data-couchbase"
    implementation "org.springframework.boot:spring-boot-starter-undertow"
    implementation "org.springframework.boot:spring-boot-starter-mail"
    implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
    implementation "org.springframework.boot:spring-boot-starter-data-redis"
    implementation "org.springframework.session:spring-session-data-redis"
    implementation "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure"

    compileOnly "org.springframework.boot:spring-boot-configuration-processor" 
}

I can see in my dependencies that spring-security-oauth2 is 2.4.1.RELEASE

If I force spring-security-oauth2 to v2.5.0 nothing changes

dependency "org.springframework.security.oauth:spring-security-oauth2:2.5.0.RELEASE"

 

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 25, 2020

Michael Reiche commented

Ok.  BasicCouchbasePersistentProperty needs to handle a null field.

 

@Override
public boolean isIdProperty() {
return isAnnotationPresent(Id.class) || super.isIdProperty()
|| (this.getField() != null && this.getFieldName().toLowerCase(Locale.ROOT).equals("id"));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants