我正在尝试使用Jetty和RESTEasy开发API。一切正常,直到我尝试注入RESTEasy服务,然后依赖项注入似乎失败。以下是到目前为止的内容。
pom.xml
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'dev' ]
2 info using npm@6.4.1
3 info using node@v10.14.2
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle vueapp02@1.0.0~predev: vueapp02@1.0.0
6 info lifecycle vueapp02@1.0.0~dev: vueapp02@1.0.0
7 verbose lifecycle vueapp02@1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle vueapp02@1.0.0~dev: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\William\Documents\mabilletterie\bitbucket\excel_configuration\vueapp02\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\Program Files\nodejs\;C:\Python34;C:\Python34\Scripts;C:\Program Files\MongoDB\Server\4.0\bin;C:\Program Files (x86)\Brackets\command;C:\Users\William\AppData\Local\Microsoft\WindowsApps;C:\Users\William\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin;C:\Users\William\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\William\AppData\Roaming\npm
9 verbose lifecycle vueapp02@1.0.0~dev: CWD: C:\Users\William\Documents\mabilletterie\bitbucket\excel_configuration\vueapp02
10 silly lifecycle vueapp02@1.0.0~dev: Args: [ '/d /s /c',
10 silly lifecycle 'cross-env NODE_ENV=development webpack-dev-server --open --hot' ]
11 silly lifecycle vueapp02@1.0.0~dev: Returned: code: 1 signal: null
12 info lifecycle vueapp02@1.0.0~dev: Failed to exec dev script
13 verbose stack Error: vueapp02@1.0.0 dev: `cross-env NODE_ENV=development webpack-dev-server --open --hot`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:182:13)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:182:13)
13 verbose stack at maybeClose (internal/child_process.js:962:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid vueapp02@1.0.0
15 verbose cwd C:\Users\William\Documents\mabilletterie\bitbucket\excel_configuration\vueapp02
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
18 verbose node v10.14.2
19 verbose npm v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error vueapp02@1.0.0 dev: `cross-env NODE_ENV=development webpack-dev-server --open --hot`
22 error Exit status 1
23 error Failed at the vueapp02@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
RestEasyApplication
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.1.4.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.14.v20181114</version>
</plugin>
</plugins>
</build>
RestEasyService
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/")
public class RestEasyApplication extends Application {}
InjectedService
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("restEasy")
public class RestEasyService {
@Inject
private InjectedService service;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getMessage() {
// If I replace this with just a hardcoded string return, it works fine.
return service.getMessage();
}
}
InjectedServiceImpl
public interface InjectedService {
String getMessage();
}
我理想的解决方案,不,将任何内容添加到public class InjectedServiceImpl implements InjectedService {
public String getMessage() {
return "Hello Universe";
}
}
或web.xml
中,因为它们是由代码生成工具生成的,因此它们将被覆盖或需要手动管理。