我正在设置一个Spring Boot应用程序,并希望主机可以访问一个系统托盘图标,该图标可以访问一些bean信息。
我目前尝试使用@Autowired细节为我的SystemTrayIcon创建一个Bean。然而,当我尝试添加SystemTrayIcon时,我会收到以下异常:
Caused by: java.awt.HeadlessException
at java.awt.TrayIcon.<init>(Unknown Source)
at java.awt.TrayIcon.<init>(Unknown Source)
at java.awt.TrayIcon.<init>(Unknown Source)
at hermes.subsrciber.systemTray.HermesTrayIcon.<init>(HermesTrayIcon.java:36)
at hermes.subscriber.boot.AppStarter.trayIcon(AppStarter.java:83)
at hermes.subscriber.boot.AppStarter$$EnhancerBySpringCGLIB$$c4f80849.CGLIB$trayIcon$3(<generated>)
at hermes.subscriber.boot.AppStarter$$EnhancerBySpringCGLIB$$c4f80849$$FastClassBySpringCGLIB$$d62ab0bd.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at hermes.subscriber.boot.AppStarter$$EnhancerBySpringCGLIB$$c4f80849.trayIcon(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 17 more
是否有办法使SpringBoot应用程序可以访问系统托盘图标?
我相信我可以在Main方法中简单地定义它(与SpringApplication.run并排),但我将无法自动装配属性。
这种设置是否可行?