我下载了正在阅读的书的源代码-Spring Security。我尝试按照下面的Gradle配置(每个项目都包含此Gradle配置)中的描述运行代码,但是在提示符处使用gradle tomcatRun
命令运行它时出现错误。
gradle文件为:
/*
* Chapter 2 Calendar
*
* @author Mick Knutson
*/
buildscript {
ext {}
repositories {
// jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}"
classpath "com.bmuschko:gradle-tomcat-plugin:${bmuschkoGradleTomcatPluginVersion}"
}
}
apply plugin: "io.spring.dependency-management"
apply plugin: "war"
apply plugin: "com.bmuschko.tomcat"
apply plugin: "com.bmuschko.tomcat-base"
// Spring Security 4, for chapter 2, version 0
version = "4.2.1-SNAPSHOT"
dependencyManagement {
imports {
mavenBom ("io.spring.platform:platform-bom:${springIoVersion}")
}
}
dependencies {
// Misc from Spring IO
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-devtools"
// Spring Dependencies:
compile "org.springframework:spring-aop"
compile "org.springframework:spring-beans"
compile "org.springframework:spring-context"
compile "org.springframework:spring-context-support"
compile "org.springframework:spring-core"
compile "org.springframework:spring-expression"
compile "org.springframework:spring-jdbc"
compile "org.springframework:spring-tx"
compile "org.springframework:spring-web"
compile "org.springframework:spring-webmvc"
compile "org.springframework:spring-test"
// Spring Security Dependencies
compile "org.springframework.security:spring-security-config"
compile "org.springframework.security:spring-security-core"
compile "org.springframework.security:spring-security-web"
compile "javax.servlet:jstl"
providedCompile "javax.servlet:javax.servlet-api"
providedCompile "javax.servlet.jsp:javax.servlet.jsp-api"
// Logging
compile "org.slf4j:slf4j-api"
compile "org.codehaus.jackson:jackson-core-asl"
compile "org.codehaus.jackson:jackson-mapper-asl"
compile "com.fasterxml.jackson.core:jackson-annotations"
compile "com.fasterxml.jackson.core:jackson-core"
compile "com.fasterxml.jackson.core:jackson-databind"
compile "javax.validation:validation-api"
compile "org.hibernate:hibernate-validator"
compile "org.hibernate:hibernate-validator-annotation-processor"
// Thymeleaf Spring
compile "org.thymeleaf:thymeleaf"
compile "org.thymeleaf:thymeleaf-spring4"
// Joda time. TO be replaced with Java 8 Time
compile "joda-time:joda-time"
// Testing:
testCompile "junit:junit"
testCompile "org.hamcrest:hamcrest-all"
testCompile "org.hamcrest:hamcrest-core"
testCompile "org.assertj:assertj-core"
// Selenium / WebDriver
testCompile "org.seleniumhq.selenium:selenium-api"
testCompile "org.seleniumhq.selenium:selenium-chrome-driver"
testCompile "org.seleniumhq.selenium:selenium-firefox-driver"
testCompile "org.seleniumhq.selenium:selenium-java"
testCompile "org.seleniumhq.selenium:selenium-support"
// Gradle Tomcat plugin
def tomcatVersion = "8.0.42"
// FIXME: These versions are not found:
// def tomcatVersion = "8.5.2"
// def tomcatVersion = "9.0.0.M6"
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"
}
//---------------------------------------------------------------------------//
task explodedWar(type: Copy) {
into "$buildDir/exploded"
with war
}
war {
baseName = "calendar"
archiveName = "${baseName}.war"
}
war.doLast {
explodedWar.execute()
}
war.dependsOn explodedWar
tomcat {
httpPort = 8080
httpsPort = 8081
enableSSL = true
contextPath = "/"
users {
user {
username = "admin"
password = "admin"
roles = ["developers", "admin"]
}
}
}
我得到的错误是:
C:\Users\user\Downloads\Spring Security 3rd Edition_Source_Code\JBCPCalendar\chapter02\chapter02.01-calendar>g
radle tomcatRun
Configuration on demand is an incubating feature.
> Task :chapter02:chapter02.01-calendar:tomcatRun
Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standa
rd format using "keytool -importkeystore -srckeystore C:\Users\user\Downloads\Spring Security 3rd Edition_Sour
ce_Code\JBCPCalendar\chapter02\chapter02.01-calendar\build\tmp\ssl\keystore -destkeystore C:\Users\user\Downlo
ads\Spring Security 3rd Edition_Source_Code\JBCPCalendar\chapter02\chapter02.01-calendar\build\tmp\ssl\keystor
e -deststoretype pkcs12".
A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [St
andardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardH
ost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webreso
urces.StandardRoot@40a58621]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:135)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4969)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5099)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 6 more
Caused by: java.lang.Error: factory already defined
at java.net.URL.setURLStreamHandlerFactory(URL.java:1112)
at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.<init>(TomcatURLStreamHandlerFactory
.java:130)
at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.getInstanceInternal(TomcatURLStreamH
andlerFactory.java:53)
at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.register(TomcatURLStreamHandlerFacto
ry.java:77)
at org.apache.catalina.webresources.StandardRoot.registerURLStreamHandlerFactory(StandardRoot.java:682
)
at org.apache.catalina.webresources.StandardRoot.initInternal(StandardRoot.java:665)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
... 10 more
> Task :chapter02:chapter02.01-calendar:tomcatRun FAILED
A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [St
andardEngine[Tomcat].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:789)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:346)
at org.apache.catalina.startup.Tomcat$start$3.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.apache.catalina.startup.Tomcat$start$3.call(Unknown Source)
at com.bmuschko.gradle.tomcat.embedded.BaseTomcatServerImpl.start(BaseTomcatServerImpl.groovy:56)
at com.bmuschko.gradle.tomcat.embedded.TomcatServer$start$9.call(Unknown Source)
at com.bmuschko.gradle.tomcat.tasks.AbstractTomcatRun.startTomcat(AbstractTomcatRun.groovy:359)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:352)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:68)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:161)
at com.bmuschko.gradle.tomcat.tasks.AbstractTomcatRun$_validateConfigurationAndStartTomcat_closure2.do
Call(AbstractTomcatRun.groovy:228)
at com.bmuschko.gradle.tomcat.tasks.AbstractTomcatRun$_validateConfigurationAndStartTomcat_closure2.do
Call(AbstractTomcatRun.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at com.bmuschko.gradle.tomcat.internal.LoggingHandler.withJdkFileLogger(LoggingHandler.groovy:56)
at com.bmuschko.gradle.tomcat.internal.LoggingHandler$withJdkFileLogger.callStatic(Unknown Source)
at com.bmuschko.gradle.tomcat.tasks.AbstractTomcatRun.validateConfigurationAndStartTomcat(AbstractTomc
atRun.groovy:227)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:352)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:68)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:161)
at com.bmuschko.gradle.tomcat.tasks.AbstractTomcatRun$_start_closure1.doCall(AbstractTomcatRun.groovy:
220)
at com.bmuschko.gradle.tomcat.tasks.AbstractTomcatRun$_start_closure1.doCall(AbstractTomcatRun.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at com.bmuschko.gradle.tomcat.internal.utils.TomcatThreadContextClassLoader.withClasspath(TomcatThread
ContextClassLoader.groovy:30)
at com.bmuschko.gradle.tomcat.internal.utils.ThreadContextClassLoader$withClasspath.call(Unknown Sourc
e)
at com.bmuschko.gradle.tomcat.tasks.AbstractTomcatRun.start(AbstractTomcatRun.groovy:219)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46
)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:801)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:768)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter
.java:131)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(D
efaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(D
efaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.
java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java
:90)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecuto
r.java:31)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTask
Executer.java:120)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTas
kExecuter.java:99)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecut
er.java:77)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectory
CreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.j
ava:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOu
tputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyEx
ecuter.java:79)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:
59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFil
esTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInp
utFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExec
uter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArt
ifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActions
Executer.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:
54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTask
Executer.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecut
er.java:34)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:
51)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(D
efaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(D
efaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.
java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java
:90)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecuto
r.java:31)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.jav
a:46)
at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execut
e(DefaultTaskExecutionGraph.java:277)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execut
e(DefaultTaskExecutionGraph.java:262)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExec
utor.java:135)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExec
utor.java:130)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecut
or.java:200)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPl
anExecutor.java:191)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.j
ava:130)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:
63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:5
5)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardH
ost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
... 1 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 6 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':chapter02:chapter02.01-calendar:tomcatRun'.
> An error occurred starting the Tomcat server.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 8s
3 actionable tasks: 1 executed, 2 up-to-date
在错误中您可以看到多行,例如:
A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [St
andardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
我一直试图找到答案以使其运行,但没有成功。
正在尝试运行的代码可以从其github's页面或here上免费下载。每章包含多个独立项目。例如,第2章包含诸如 chapter02.01-calendar , chapter02.02-calendar 等项目,等等……您只需进入文件夹您的命令行提示符,并按照本书GitHub页上的建议执行gradle tomcatRun