springboot-01问题:将程序打包成jar包运行出错

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)

记录问题!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值