小编wil*_*ing的帖子

Java Spring中的重载控制器方法

我有一个控制器,需要使用不同的URL参数表现不同.像这样的东西:

@RequestMapping(method = RequestMethod.GET)
public A getA(@RequestParam int id, @RequestParam String query) {
    ...
}


@RequestMapping(method = RequestMethod.GET)
public A getA(@RequestParam int id) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用,我得到以下异常:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map '[controller name]' bean method 
Run Code Online (Sandbox Code Playgroud)

应用程序是否有一种方法可以根据URL参数选择方法?

java spring

18
推荐指数
1
解决办法
8295
查看次数

在heroku上找不到gunicorn

我想在Heroku上部署一个非常基本的Django应用。我按照说明进行操作,但是浏览器显示了Heroku错误页面,并且heroku日志显示

bash: gunicorn: command not found
Run Code Online (Sandbox Code Playgroud)

我的requirements.txt文件中包含gunicorn,并按照文档说明配置了wsgi.py和Procfile。我还能尝试什么?

编辑:我也尝试在Heroku(heroku run pip install gunicorn)上手动安装gunicorn ,效果很好,所以我很确定已经安装了gunicorn。为什么Heroku找不到它?

编辑2:看来我可以手动安装gunicorn(heroku run bash然后pip install gunicorn

~ $ gunicorn
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: No application module specified.
Run Code Online (Sandbox Code Playgroud)

但是当我注销并再次登录bash时,我得到:

~ $ gunicorn
bash: gunicorn: command not found
Run Code Online (Sandbox Code Playgroud)

Heroku似乎已安装,但随后丢弃了Gunicorn。怎么可能?

django heroku gunicorn

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

在OS X El Capitan上安装Scrapy

我试图在El Capitan上安装Scrapy但尚未成功.我使用时会发生这种情况pip install Scrapy:

#include <openssl/opensslv.h>

         ^

1 error generated.

error: command 'cc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /<scrapy_project>/venv/bin/python -c "import setuptools, tokenize;__file__='/<scrapy_project>/venv/build/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/p6/jvf54l7d5c7dntzm6d3rfc3w0000gn/T/pip-D2QIZq-record/install-record.txt --single-version-externally-managed --compile --install-headers /<scrapy_project>/venv/include/site/python2.7 failed with error code 1 in /<scrapy_project>/venv/build/cryptography
Run Code Online (Sandbox Code Playgroud)

我的Xcode和Xcode命令工具是最新的.根据http://doc.scrapy.org/en/latest/intro/install.html#intro-install,我尝试使用和不使用自制程序的方法安装Scrapy

编辑:我做了以下事情:

  • brew install openssl && brew link openssl --force 根据Craicerjack的建议
  • pip install cryptography
  • pip install scrapy

一切都没有任何错误.但scrapy --version抛出此错误:

ImportError: dlopen(/<scrapy_project>/venv/lib/python2.7/site-packages/cryptography/hazmat/bindings/_openssl.so, 2): Symbol not found: _BIO_new_CMS
  Referenced from: …
Run Code Online (Sandbox Code Playgroud)

python scrapy

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

如何处理Java中的参数区分?

我需要一个需要不同参数的方法,并根据参数表现不同,如下例所示:

public void doSomething(A a, B b, C c) {
    doSomeGeneralStuff();

    if a.isPresent() {
        doSomethingWithA();
    }
    if b.isPresent() {
        doSomethingWithB();
    }
    if c.isPresent() {
        doSomethingWithC();
    }
}
Run Code Online (Sandbox Code Playgroud)

另一种选择是:

public void doSomething(A a) {
    doSomeGeneralStuff();
    doSomethingWithA();
}
public void doSomething(B b) {
    doSomeGeneralStuff();
    doSomethingWithB();
}
public void doSomething(C c) {
    doSomeGeneralStuff();
    doSomethingWithC();
}
Run Code Online (Sandbox Code Playgroud)

但是在第二个例子中我会有一堆冗余代码,这就是为什么我仍然不满意.还有哪些其他模式处理这个问题?

java

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

标签 统计

java ×2

django ×1

gunicorn ×1

heroku ×1

python ×1

scrapy ×1

spring ×1