小编use*_*867的帖子

使用未声明的板条箱或模块,“use crate_name::schema::posts”并不总是有效

actix-web我正在尝试通过将 Rust 与和 一起使用来学习 Rust diesel

当我尝试使用板条箱名称导入/使用架构时,它仅在文件中有效example.rs,但在post.rs文件中无效。这两个文件都嵌套在它们自己的文件夹中,我使用的命令如下:

use web_project_core::schema::posts;

当我使用另一个命令时,它可以在以下命令中工作,post.rs但不能在以下命令中工作example.rs

use super::super::schema::posts;

我缺少什么?

// Cargo.toml
[lib]
name = "web_project_core"
path = "src/lib.rs"

[[bin]]
name = "main"
path = "src/main.rs"
Run Code Online (Sandbox Code Playgroud)
// main.rs

use actix_web::{App, HttpServer};

mod handlers;
Run Code Online (Sandbox Code Playgroud)
// lib.rs
#[macro_use]
extern crate diesel;
extern crate dotenv;

use diesel::prelude::*;
use diesel::pg::PgConnection;
use dotenv::dotenv;
use std::env;

pub mod schema;
pub mod modelz;
Run Code Online (Sandbox Code Playgroud)
// post.rs

use serde::{Serialize, Deserialize};
use nanoid::generate;

use super::super::schema::posts;        // <-- …
Run Code Online (Sandbox Code Playgroud)

rust actix-web

11
推荐指数
1
解决办法
4万
查看次数

java.lang.ClassNotFoundException:带有maven-jar-plugin的org.springframework.boot.SpringApplication

我是Spring和Maven的新手。我正在尝试运行一个简单应用程序的jar,但收到以下错误:

java -jar target/gs-rest-service-0.0.1-SNAPSHOT.jar 
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
    at hello.Application.main(Application.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more
Run Code Online (Sandbox Code Playgroud)

这是pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>gs-rest-service</groupId>
  <artifactId>gs-rest-service</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>MyApp</name>
  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>hello.Application</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.3.10.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>1.5.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
        <version>1.5.5.RELEASE</version>
    </dependency>
  </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

这是需要SpringApplication的主要类:

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc maven

5
推荐指数
1
解决办法
4758
查看次数

使用inject函数不能使用beforeEach

这是来自karma.conf.js文件:

module.exports = function (config) {
  config.set({
      frameworks: ['mocha', 'chai'],
      files: [
        'bower_components/angular/angular.js',
        'bower_components/angular-mocks/angular-mocks.js',
        'public/ng-app/module.js',
        'public/ng-app/**/*.js',
        'test/ng/**/*.spec.js'
      ],
  ...
Run Code Online (Sandbox Code Playgroud)

我试图使用beforeEach函数注入这样:

describe('my.test', function () {
  beforeEach(module('app'));

  var MyService;
  beforeEach(inject(function (_MyService_) {
    MyService = _MyService_;
  }));

  describe('#send', function () {
    it('exists', function () {
      expect(MyService.save).to.exist;
    });
  });

});
Run Code Online (Sandbox Code Playgroud)

但是beforeEach(inject(function(...)...);当我尝试运行测试时,部分代码会导致此错误:

PhantomJS 1.9.8 (Windows 8 0.0.0) my.test "before each" hook: workFn for "exists" FAILED
        Error: [$injector:modulerr] Failed to instantiate module ng due to:
        TypeError: 'undefined' is not an object (evaluating 'Function.prototype.bind.apply')
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚问题是什么.有人有什么想法吗?谢谢.

angularjs angular-mock karma-mocha

3
推荐指数
1
解决办法
2120
查看次数

使用bcrypt-nodejs的未定义函数

我正在使用bcrypt-nodejs在预保存函数中散列密码.我无法弄清楚为什么我继续在bcrypt.hash的回调函数中收到错误'[TypeError:undefined is not a function]'.

var mongoose = require('mongoose'),
    validate = require('mongoose-validate'),
    bcrypt   = require('bcrypt-nodejs'),
    SALT_WORK_FACTOR = 10,
    REQUIRED_PASSWORD_LENGTH = 8;

function validateStringLength (value) {
    return value && value.length >= REQUIRED_PASSWORD_LENGTH;
}

var schema = mongoose.Schema({
    email: {type: String,
            required: true,
            unique: true,
            validate: [validate.email, 'is not a valid email address']
    },
    passHash: {type: String,
                required: true,
                validate: [validateStringLength, 'The password must be of min ' + REQUIRED_PASSWORD_LENGTH + ' characters length.']}
});

schema.pre('save', function (next) {
    var self = …
Run Code Online (Sandbox Code Playgroud)

bcrypt mongoose node.js

2
推荐指数
1
解决办法
5868
查看次数