springboot-01问题:将程序打包成jar包运行出错
在pom.xml中加入插件
<build>
<!--可以将应用打包成jar包-->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
编写一个简单的helloworld
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "Hello World!";
}
}
主程序:
@SpringBootApplication
class HelloWorldMainApplication {
public static void main(String[] args) {
//启动springboot应用
SpringApplication.run(HelloWorldMainApplication.class,args);
}
}
用idea打包成jar包
在cmd运行java -jar spring-boot-01-helloworld-1.0-SNAPSHOT.jar
报错:
Exception in thread "main" java.lang.IllegalAccessException: Class org.springframework.boot.loader.MainMethodRunner can not access a member of class com.fsunicom.HelloWorldMainApplication with modifiers "public static"
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown Source)
at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
记录问题!