草庐IT

mongodb - Spring Data MongoDB 在 org.springframework.data.mapping.PropertyPath 找不到类型的属性

coder 2023-11-01 原文

我使用的是 Spring Data MongoDB 1.4.2.Release 版本。对于 Spring Data MongoDB,我在一个位置创建了自定义存储库接口(interface)和实现,并创建了自定义查询函数 getUsersName(Users users)

但是我仍然遇到以下异常:

Caused by: org.springframework.data.mapping.PropertyReferenceException:
  No property get found for type Users! at org.springframework.data.mapping.PropertyPath.     (PropertyPath.java:75) at
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) at 
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359) at
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359) at
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) at
    org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) at
    org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) at
    org.springframework.data.repository.query.parser.Part.(Part.java:76) at
    org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:201) at
    org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:291) at 
    org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:271) at 
    org.springframework.data.repository.query.parser.PartTree.(PartTree.java:80) at 
    org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.(PartTreeMongoQuery.java:47)

下面是我的 Spring Data MongoDB 结构:

      /*  Users Domain Object */

        @Document(collection = "users")
        public class Users {

        @Id
        private ObjectId id;

        @Field ("last_name")
        private String last_name;

        @Field ("first_name")
        private String first_name;

       public String getLast_name() {
          return last_name;
      }

      public void setLast_name(String last_name) {
        this.last_name = last_name;
     }

      public String getFirst_name() {
        return first_name;
     }

     public void setFirst_name(String first_name) {
        this.first_name = first_name;
     }
}

       /* UsersRepository.java main interface */

        @Repository
        public interface UsersRepository extends MongoRepository<Users,String>, UsersRepositoryCustom { 

             List findUsersById(String id);

         }

       /* UsersRepositoryCustom.java custom interface */

        @Repository
        public interface UsersRepositoryCustom {

           List<Users> getUsersName(Users users);
        }

       /* UsersRepositoryImpl.java custom interface implementation */

        @Component
        public class UsersRepositoryImpl implements UsersRepositoryCustom {

        @Autowired
        MongoOperations mongoOperations;


        @Override
        public List<Users> getUsersName(Users users) {
            return mongoOperations.find(
                    Query.query(Criteria.where("first_name").is(users.getFirst_name()).and("last_name").is(users.getLast_name())), Users.class);
        }

       /* Mongo Test function inside Spring JUnit Test class calling custom function with main UsersRepository interface */

        @Autowired
        private UsersRepository usersRepository;

        @Test
        public void getUsersName() {

            Users users = new Users();
            users.setFirst_name("James");`enter code here`
            users.setLast_name("Oliver");
            List<Users> usersDetails = usersRepository.getUsersName(users);
            System.out.println("users List" + usersDetails.size());


            Assert.assertTrue(usersDetails.size() > 0);
        }

最佳答案

您的存储库接口(interface)中的查询方法声明无效。正如 reference documentation 中明确指出的那样,查询方法需要以get…Byread_Byfind…Byquery…by开头。

关于mongodb - Spring Data MongoDB 在 org.springframework.data.mapping.PropertyPath 找不到类型的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23657661/

有关mongodb - Spring Data MongoDB 在 org.springframework.data.mapping.PropertyPath 找不到类型的属性的更多相关文章

  1. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  2. ruby-on-rails - 更好的替代方法 try( :output). try( :data). try( :name)? - 2

    “输出”是一个序列化的OpenStruct。定义标题try(:output).try(:data).try(:title)结束什么会更好?:) 最佳答案 或者只是这样:deftitleoutput.data.titlerescuenilend 关于ruby-on-rails-更好的替代方法try(:output).try(:data).try(:name)?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c

  3. ruby-on-rails - rbenv:从 RVM 移动到 rbenv 后,在 Jenkins 执行 shell 中找不到命令 - 2

    我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions

  4. ruby-on-rails - 找不到 gem railties (>= 0.a) (Gem::GemNotFoundException) - 2

    我已经看到了一些其他的问题,尝试了他们的建议,但没有一个对我有用。我已经使用Rails大约一年了,刚刚开始一个新的Rails项目,突然遇到了问题。我卸载并尝试重新安装所有Ruby和Rails。Ruby很好,但Rails不行。当我输入railss时,我得到了can'tfindgemrailties。我当前的Ruby版本是ruby2.2.2p95(2015-04-13修订版50295)[x86_64-darwin15],尽管我一直在尝试通过rbenv设置ruby​​2.3.0。如果我尝试rails-v查看我正在运行的版本,我会得到同样的错误。我使用的是MacOSXElCapitan版本10

  5. 即使安装了 gem,Ruby 也找不到所需的库 - 2

    我花了几天时间尝试安装ruby​​1.9.2并让它与gems一起工作:-/我最终放弃了我的MacOSX10.6机器,下面是我的Ubuntu机器上的当前状态。任何建议将不胜感激!#rubytest.rb:29:in`require':nosuchfiletoload--mongo(LoadError)from:29:in`require'fromtest.rb:1:in`'#cattest.rbrequire'mongo'db=Mongo::Connection.new.db("mydb")#gemwhichmongo/usr/local/rvm/gems/ruby-1.9.2-p0/g

  6. ruby - Sinatra 找不到 View 目录 - 2

    我正在尝试以一种更类似于普通RubyGem结构的方式构建我的Sinatra应用程序。我有以下文件树:.├──app.rb├──config.ru├──Gemfile├──Gemfile.lock├──helpers│  ├──dbconfig.rb│  ├──functions.rb│  └──init.rb├──hidden│  └──Rakefile├──lib│  ├──admin.rb│  ├──api.rb│  ├──indexer.rb│  ├──init.rb│  └──magnet.rb├──models│  ├──init.rb│  ├──invite.rb│  ├─

  7. ruby - 在 SUSE 上找不到 Ruby 的头文件? - 2

    我正在尝试在SUSEEnterprise11SP3上安装compass。我得到以下信息。有什么想法吗?geminstallcompassBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingcompass:ERROR:Failedtobuildgemnativeextension./usr/bin/rubyextconf.rbmkmf.rbcan'tfindheaderfilesforrubyat/usr/lib64/ruby/ruby.hextconffailed,exitcode1Gemfileswi

  8. ruby - 在 ruby​​ 中使用 .try 函数和 .map 函数 - 2

    我需要从json记录中获取一些值并像下面这样提取curr_json_doc['title']['genre'].map{|s|s['name']}.join(',')但对于某些记录,curr_json_doc['title']['genre']可以为空。所以我想对map和join()使用try函数。我试过如下curr_json_doc['title']['genre'].try(:map,{|s|s['name']}).try(:join,(','))但是没用。 最佳答案 你没有正确传递block。block被传递给参数括号外的方法

  9. ruby-on-rails - Heroku 找不到 SecureRandom - 2

    我的heroku应用崩溃了,因为它找不到模块“SecureRandom”。我在gemfile中指定了我的Ruby版本,我的计算机、gemfile和Heroku似乎都匹配Ruby版本号,尽管不是补丁号。其他帖子建议将usr/bin/heroku指向特定的Ruby文件,但我不确定该怎么做(我的应用程序中没有Herokubin)。这看起来像是Ruby版本错误。我该如何解决这个问题?classOrderItemHeroku日志:/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependenci

  10. ruby - rackup:找不到命令 - 2

    我目前正在做一个需要在ubuntu11.04上使用rackup命令的项目,但我收到一个错误:-bash:rackup:commandnotfound。我已经安装了rails和rackruby​​gems。任何帮助都会很棒! 最佳答案 如果你正在使用bundler那么也许你需要使用bundleexecbundleexecrackup 关于ruby-rackup:找不到命令,我们在StackOverflow上找到一个类似的问题: https://stackover

随机推荐