Весенняя война не запускается при запуске
Я пытаюсь сделать веб-сервис, используя Spring-Boot с Gretty. Хорошо работает при звонке appStart
в Gradle, но он будет отображать ошибку при вызове appStartWar
,
Это ошибка:
Exception in thread "main" java.lang.ClassNotFoundException: com.example.server.Application
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at java_lang_Class$forName.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at org.akhikhl.gretty.SpringBootServerManager.startServer(SpringBootServerManager.groovy:46)
at org.akhikhl.gretty.ServerManager$startServer$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.akhikhl.gretty.Runner.run(Runner.groovy:70)
at org.akhikhl.gretty.Runner.this$2$run(Runner.groovy)
at org.akhikhl.gretty.Runner$this$2$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at org.akhikhl.gretty.Runner.main(Runner.groovy:48)
Exception in thread "Thread-18" org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe'' finished with non-zero exit value 1
at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:365)
at org.gradle.process.internal.DefaultJavaExecAction.execute(DefaultJavaExecAction.java:31)
at org.gradle.api.internal.file.DefaultFileOperations.javaexec(DefaultFileOperations.java:159)
at org.gradle.api.internal.project.AbstractProject.javaexec(AbstractProject.java:793)
at org.gradle.api.Project$javaexec$8.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.akhikhl.gretty.DefaultLauncher.javaExec(DefaultLauncher.groovy:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:368)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at org.akhikhl.gretty.LauncherBase$_launchThread_closure6.doCall(LauncherBase.groovy:216)
at org.akhikhl.gretty.LauncherBase$_launchThread_closure6.doCall(LauncherBase.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:278)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
at groovy.lang.Closure.call(Closure.java:423)
at groovy.lang.Closure.call(Closure.java:417)
at groovy.lang.Closure.run(Closure.java:504)
at java.lang.Thread.run(Thread.java:744)
Кажется, что он не мог найти основной класс в файле войны, но com.example.server.Application
действительно существует в войне с путем WEB-INF/classes/com/example/server
build.gradle
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'spring-boot'
apply plugin: 'org.akhikhl.gretty'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.1.8'
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.2.RELEASE'
}
}
dependencies{
compile 'org.springframework.boot:spring-boot-starter-web:1.2.2.RELEASE'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
}
gretty {
springBoot = true
springBootVersion = '1.2.2.RELEASE'
httpsEnabled = true
}
Application.java
@RestController
@SpringBootApplication
class Application extends SpringBootServletInitializer {
public static void main( String[] args ) {
SpringApplication.run( Application.class, args );
}
@Override
protected SpringApplicationBuilder configure( SpringApplicationBuilder builder ) {
return builder.sources( Application.class );
}
@RequestMapping( value = "test", method = RequestMethod.GET )
public String test() {
return "success";
}
}
Любая помощь приветствуется:)
Вот мой проект в Gitlab по ссылке
Я пытался развернуть войну на tomcat-7 напрямую, но она также не удалась. Так что я думаю, что это не изрядная проблема.
журнал
javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:160)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5513)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1081)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1877)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalAccessException: Class org.springframework.web.SpringServletContainerInitializer can not access a member of class com.example.server.Application with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:157)
... 12 more
1 ответ
Решение
Ваш
@RestController
@SpringBootApplication
class Application extends SpringBootServletInitializer
класс должен быть обнародован:
@RestController
@SpringBootApplication
public class Application extends SpringBootServletInitializer
В своем нынешнем виде он защищен пакетом и не может быть создан с помощью отражения. (по умолчанию)