Sprig Boot中的com.mongodb.util.JSONParseException?

时间:2017-12-04 09:12:23

标签: java mongodb spring-boot spring-data

我尝试使用@Query注释创建自定义查询。但它会引发一些错误。

这是我的存储库

package com.springboot.springmongodb.user;
import java.util.List;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface UserRepository extends CrudRepository<User, String>{
    @Override
    User findOne(String id);

    @Transactional(readOnly=false)
    @Query("SELECT user FROM User user WHERE user.username = :username")
    public List<User> findByUsername(@Param("username") String username);

}

我想为check username创建自定义查询。

这是我得到的错误。

  

2017-12-04 14:46:10.413 WARN 1452 --- [主要]   ationConfigEmbeddedWebApplicationContext:遇到异常   在上下文初始化期间 - 取消刷新尝试:   org.springframework.beans.factory.BeanCreationException:错误   创建名为&#39; springSecurityFilterChain&#39;在课堂上定义   路径资源   [组织/ springframework的/安全/配置/注解/网络/配置/ WebSecurityConfiguration.class]:   通过工厂方法进行Bean实例化失败;嵌套异常是   org.springframework.beans.BeanInstantiationException:失败   实例化[javax.servlet.Filter]:工厂方法   &#39; springSecurityFilterChain&#39;抛出异常;嵌套异常是   org.springframework.beans.factory.UnsatisfiedDependencyException:   创建名称为&#39; userDetailsS​​ervice&#39;:不满意的bean时出错   通过字段“userRep”表示的依赖性;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   创建名为&#39; userRepository&#39;的bean:调用init方法   失败;嵌套异常是com.mongodb.util.JSONParseException:   SELECT user FROM User user WHERE user.username =:username ^

1 个答案:

答案 0 :(得分:1)

该异常表示您提供的Dim FindRng As Range Dim FiltCol As Long With rData Set FindRng = .Rows(1).Find(what:="Vlookup") If Not FindRng Is Nothing Then ' Find was successful FiltCol = FindRng.Column ' get the column number where "Vlookup" was found Else ' find unable to find "Vlookup" MsgBox "Find Error!" Exit Sub End If .AutoFilter Field:=FiltCol, Criteria1:="Class" ' filter criterion End With 被视为JSON。看看你的进口导致我们的原因:

@Query

虽然您的查询import org.springframework.data.mongodb.repository.Query; 对JPA(SQL)有效,但它对MongoDB无效。更改导入以适合您的数据库或更改查询以适应它。

有效的mongoDB类似于Spring Data MongoDB example

SELECT user FROM User user WHERE user.username = :username

...来自Spring Data JPA example的有效JPA声明:

public interface PersonRepository extends MongoRepository<Person, String>

  @Query("{ 'username' : ?0 }")
  List<Person> findByThePersonsFirstname(String firstname);

}

这需要导入org.springframework.data.jpa.repository.Query