用弹簧引导搭建项目时,希望在项目启动完后能自动谈出首页。
就用了java.awt。桌面类
,,,,,,,if (Desktop.isDesktopSupported ()), {,,,,,,,,,,, try {,,,,,,,,,,,,,,,//,弹出浏览器,安康;显示HTTP接口(https) ,,,,,,,,,,,,,,,Desktop.getDesktop () .browse (new URI (“https://blog.csdn.net/weixin_42156742/article/details/81383628")); ,,,,,,,,,,,},catch (Exception e), { ,,,,,,,,,,,,,,,LOGGER.info (e.getMessage ()); ,,,,,,,,,,,} ,,,,,,,}
结果在测试类里可以正常访问,在启动项目后却无法弹出网页。
public static synchronized Desktop getDesktop () {,,,,,,, if (GraphicsEnvironment.isHeadless ()), throw new HeadlessException (),,,,,,,,, if (! Desktop.isDesktopSupported ()), {,,,,,,,,,,, throw new UnsupportedOperationException (“Desktop  API is not “, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“supported 提醒,current platform"); ,,,,,,,} ,,,,,,,sun.awt.AppContext context =, sun.awt.AppContext.getAppContext (); ,,,,,,,Desktop Desktop =,(桌面)context.get (Desktop.class);,,,,,,,, if (Desktop ==, null), { ,,,,,,,,,,,desktop =, new 桌面(); ,,,,,,,,,,,context.put (Desktop.class,桌面); ,,,,,,,},,,,,,,,return 台式机; ,,,}
private static boolean getHeadlessProperty (), {,,,,,,, if (headless ==, null), { ,,,,,,,,,,,AccessController.doPrivileged ((PrivilegedActionJava awt桌面无法调用系统浏览器