我的名字Daniel和我是Java和WebApplications的初学者。 我有一个问题,因为我的NullPointerException有问题。
我学习Spring依赖注入。我弄错了,但我找不到。 谢谢你的帮助。
public class EmailServiceImpl implements MessageService {
@Override
public String getMessage(String messageName) {
return "EMAIL_SERVICE";
}
}
public class NotifyServiceImpl implements MessageService {
@Override
public String getMessage(String messageName) {
return "NOTIFY_SERVICE";
}
}
@Component
public interface MessageService {
public String getMessage(String messageName);
}
@Configuration
public class DIConfiguration {
@Bean
public MessageService getMessageService(){
return new NotifyServiceImpl();
}
}
//vaadin init first class
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(DIConfiguration.class);
context.refresh();
MessageService message = context.getBean(MessageService.class);
Notification.show(message.getMessage("dfsa"));
//it works
//context.close();
//different class
//it doesn't work
@Autowired
private MessageService messages;
Notification.show(messages.getMessage("first"));
//堆栈跟踪//
/home/daniel/dev/apache-tomcat-8.0.3/bin/catalina.sh run
Using CATALINA_BASE: /home/daniel/.IntelliJIdea13/system/tomcat/Unnamed_MyProject
Using CATALINA_HOME: /home/daniel/dev/apache-tomcat-8.0.3
Using CATALINA_TMPDIR: /home/daniel/dev/apache-tomcat-8.0.3/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_05
Using CLASSPATH: /home/daniel/dev/apache-tomcat-8.0.3/bin/bootstrap.jar:/home/daniel/dev/apache-tomcat-8.0.3/bin/tomcat-juli.jar
[2014-10-21 04:05:04,571] Artifact MyProject:war exploded: Server is not connected. Deploy is not available.
21-Oct-2014 16:05:05.150 INFO [main] org.apache.catalina.core.AprLifecycleListener.init The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /home/daniel/dev/idea-IU-135.1289/bin::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
21-Oct-2014 16:05:05.455 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
21-Oct-2014 16:05:05.472 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
21-Oct-2014 16:05:05.476 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
21-Oct-2014 16:05:05.478 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
21-Oct-2014 16:05:05.478 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 632 ms
21-Oct-2014 16:05:05.505 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
21-Oct-2014 16:05:05.505 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.3
21-Oct-2014 16:05:05.515 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
21-Oct-2014 16:05:05.521 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
21-Oct-2014 16:05:05.522 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 43 ms
Connected to server
[2014-10-21 04:05:05,687] Artifact MyProject:war exploded: Artifact is being deployed, please wait...
21-Oct-2014 16:05:05.769 WARNING [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
paź 21, 2014 4:05:08 PM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration@7846684d]
[2014-10-21 04:05:08,836] Artifact MyProject:war exploded: Artifact is deployed successfully
[2014-10-21 04:05:08,836] Artifact MyProject:war exploded: Deploy took 3 149 milliseconds
paź 21, 2014 4:05:09 PM com.vaadin.server.DefaultDeploymentConfiguration checkProductionMode
WARNING:
=================================================================
Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
To show debug window, add ?debug to your application URL.
=================================================================
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework addAtmosphereHandler
INFO: Installed AtmosphereHandler com.vaadin.server.communication.PushHandler$1 mapped to context-path: /
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework addAtmosphereHandler
INFO: Installed the following AtmosphereInterceptor mapped to AtmosphereHandler com.vaadin.server.communication.PushHandler$1
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework doInitParams
WARNING: SessionSupport error. Make sure you define org.atmosphere.cpr.SessionSupport as a listener in web.xml instead
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework autoConfigureService
INFO: Atmosphere is using org.atmosphere.cpr.DefaultAnnotationProcessor for processing annotation
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.DefaultAnnotationProcessor configure
INFO: AnnotationProcessor class org.atmosphere.cpr.DefaultAnnotationProcessor$ServletContainerInitializerAnnotationProcessor being used
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.DefaultAnnotationProcessor fallbackToManualAnnotatedClasses
WARNING: Unable to detect annotations. Application may fail to deploy.
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework autoDetectWebSocketHandler
INFO: Auto detecting WebSocketHandler in /WEB-INF/classes/
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework initWebSocket
INFO: Installed WebSocketProtocol org.atmosphere.websocket.protocol.SimpleHttpProtocol
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework configureAtmosphereInterceptor
INFO: Installing Default AtmosphereInterceptor
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.CorsInterceptor : CORS Interceptor Support
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.CacheHeadersInterceptor : Default Response's Headers Interceptor
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.PaddingAtmosphereInterceptor : Browser Padding Interceptor Support
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.AndroidAtmosphereInterceptor : Android Interceptor Support
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.HeartbeatInterceptor : Heartbeat Interceptor Support
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.SSEAtmosphereInterceptor : SSE Interceptor Support
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.JSONPAtmosphereInterceptor : JSONP Interceptor Support
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.JavaScriptProtocol : Atmosphere JavaScript Protocol
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.WebSocketMessageSuspendInterceptor : org.atmosphere.interceptor.WebSocketMessageSuspendInterceptor
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.OnDisconnectInterceptor : Browser disconnection detection
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework newAInterceptor
INFO: org.atmosphere.interceptor.IdleResourceInterceptor : org.atmosphere.interceptor.IdleResourceInterceptor
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework configureAtmosphereInterceptor
INFO: Set org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults to disable them.
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Using EndpointMapper class org.atmosphere.util.DefaultEndpointMapper
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Using BroadcasterCache: org.atmosphere.cache.UUIDBroadcasterCache
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Default Broadcaster Class: org.atmosphere.cpr.DefaultBroadcaster
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Broadcaster Polling Wait Time 100
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Shared ExecutorService supported: true
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Messaging Thread Pool Size: Unlimited
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Async I/O Thread Pool Size: 200
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Using BroadcasterFactory: org.atmosphere.cpr.DefaultBroadcasterFactory
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Using WebSocketProcessor: org.atmosphere.websocket.DefaultWebSocketProcessor
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: HttpSession supported: true
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Atmosphere is using DefaultAtmosphereObjectFactory for dependency injection and object creation
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Atmosphere is using async support: org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket running under container: Apache Tomcat/8.0.3 using javax.servlet/3.0
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework info
INFO: Atmosphere Framework 2.1.2.vaadin5 started.
paź 21, 2014 4:05:09 PM org.atmosphere.cpr.AtmosphereFramework interceptor
INFO: Installed AtmosphereInterceptor Track Message Size Interceptor using | with priority BEFORE_DEFAULT
16:05:10.740 [http-nio-8080-exec-6] DEBUG o.s.core.env.StandardEnvironment - Initializing new StandardEnvironment
16:05:10.746 [http-nio-8080-exec-6] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
16:05:10.748 [http-nio-8080-exec-6] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
16:05:10.748 [http-nio-8080-exec-6] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
16:05:10.776 [http-nio-8080-exec-6] DEBUG o.s.c.a.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
16:05:10.797 [http-nio-8080-exec-6] INFO o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a521c9d: startup date [Tue Oct 21 16:05:10 CEST 2014]; root of context hierarchy
16:05:10.798 [http-nio-8080-exec-6] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Bean factory for org.springframework.context.annotation.AnnotationConfigApplicationContext@2a521c9d: org.springframework.beans.factory.support.DefaultListableBeanFactory@167180b0: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,DIConfiguration]; root of factory hierarchy
16:05:10.812 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
16:05:10.813 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
16:05:10.834 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references
16:05:10.837 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
16:05:10.873 [http-nio-8080-exec-6] DEBUG o.s.c.a.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method pl.infotower.spring.DIConfiguration.getMessageService()
16:05:10.982 [http-nio-8080-exec-6] DEBUG o.s.c.a.ConfigurationClassEnhancer - Successfully enhanced pl.infotower.spring.DIConfiguration; enhanced class name is: pl.infotower.spring.DIConfiguration$$EnhancerByCGLIB$$5075f3a1
16:05:10.982 [http-nio-8080-exec-6] DEBUG o.s.c.a.ConfigurationClassPostProcessor - Replacing bean definition 'DIConfiguration' existing class name 'pl.infotower.spring.DIConfiguration' with enhanced class name 'pl.infotower.spring.DIConfiguration$$EnhancerByCGLIB$$5075f3a1'
16:05:10.985 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
16:05:10.986 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
16:05:10.987 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' to allow for resolving potential circular references
16:05:10.988 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
16:05:10.988 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
16:05:10.988 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
16:05:10.989 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' to allow for resolving potential circular references
16:05:10.989 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
16:05:10.989 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
16:05:10.989 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
16:05:10.996 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' to allow for resolving potential circular references
16:05:10.996 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
16:05:10.996 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
16:05:10.996 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
16:05:10.996 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' to allow for resolving potential circular references
16:05:10.996 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
16:05:10.996 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
16:05:10.997 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
16:05:10.997 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor' to allow for resolving potential circular references
16:05:10.997 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
16:05:11.003 [http-nio-8080-exec-6] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@603be86e]
16:05:11.007 [http-nio-8080-exec-6] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@7c485f83]
16:05:11.009 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@167180b0: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,DIConfiguration,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,getMessageService]; root of factory hierarchy
16:05:11.010 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
16:05:11.010 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
16:05:11.010 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
16:05:11.010 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
16:05:11.010 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'DIConfiguration'
16:05:11.010 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'DIConfiguration'
16:05:11.013 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'DIConfiguration' to allow for resolving potential circular references
16:05:11.054 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'DIConfiguration'
16:05:11.054 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
16:05:11.054 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
16:05:11.055 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'getMessageService'
16:05:11.055 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'getMessageService'
16:05:11.058 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'DIConfiguration'
16:05:11.095 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'getMessageService' to allow for resolving potential circular references
16:05:11.099 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'getMessageService'
16:05:11.103 [http-nio-8080-exec-6] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@56c62d60]
16:05:11.103 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
16:05:11.107 [http-nio-8080-exec-6] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
16:05:11.107 [http-nio-8080-exec-6] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
16:05:11.108 [http-nio-8080-exec-6] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
16:05:11.108 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'getMessageService'
21-Oct-2014 16:05:15.516 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /home/daniel/dev/apache-tomcat-8.0.3/webapps/manager
paź 21, 2014 4:05:16 PM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
java.lang.NullPointerException
at pl.infotower.views.HelpView$1.buttonClick(HelpView.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:979)
at com.vaadin.ui.Button.fireClick(Button.java:393)
at com.vaadin.ui.Button$1.click(Button.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:287)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:180)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:93)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1402)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
当我使用
时Notification.show(messages.getMessage("first"));
抛出NullPointerEx。
答案 0 :(得分:1)
Vaadin对象本身不受Spring容器控制。因此,@Autowired
类中使用的HelpView
注释不受尊重。要使示例工作,您需要进行一些集成工作。在互联网上的博客和教程中可以找到几种不同的方法。
一种方法,无需更改示例代码即可使用@AspectJ。我将使用Maven作为管理工具来解释它。如果您以其他方式管理项目,请采用所需的步骤。
要点:使用@Configurable
注释需要自动装配/注入功能的vaadin类(或任何其他非spring类)。不要忘记在下面显示的应用程序上下文文件中添加<context:spring-configured />
条目。因此,AspectJ将完成所需的所有魔术:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
@Configured
public class HelpView extends VerticalLayout implements View {
@Autowired
private MessageService messages;
...
让AspectJ工作
AspectJ本身需要一些配置。首先必须调用 AspectJ编译器。使用Maven,您可以使用以下插件实现这一点(将xml作为<plugins />
的子项复制到您的pom.xml):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
其次,需要 AspectJ运行时和 Spring的AOP资源。将以下内容复制到Maven <dependencies />
元素(在pom.xml中):
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.2.1.RELEASE</version>
</dependency>
最后,您需要应用程序上下文文件中的配置条目(Bean.xml,root-context.xml,applicationContext.xml或bean声明xml文件的名称)。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:spring-configured />
<强>版本强> 我选择的版本号在我的环境中很好地协同工作。也许人们必须根据自己的环境改变它们。
答案 1 :(得分:0)
我现在错误在HelpView中,但我现在不知道是什么原因。
package pl.xxx.views;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.VerticalLayout;
import org.springframework.beans.factory.annotation.Autowired;
import pl.xxx.data.ExampleUtil;
import pl.xxx.spring.di.MessageService;
import pl.xxx.models.CalculatorModel;
import pl.xxx.ui.MainMenuComponent;
import pl.xxx.presenters.CalculatorPresenter;
public class HelpView extends VerticalLayout implements View {
@Autowired
private MessageService messages;
public HelpView() {
setSizeFull();
setSpacing(true);
addComponent(new MainMenuComponent());
addComponent(headingLabel());
addComponent(someText());
addComponent(redirectButton());
addComponent(calculator());
}
@Override
public void enter(ViewChangeEvent event) {
Notification.show("Showing view: Help!");
}
private Label headingLabel() {
return new Label("Help");
}
private Label someText() {
Label label = new Label(ExampleUtil.lorem);
label.setContentMode(ContentMode.HTML);
return label;
}
private Button redirectButton(){
Button button = new Button("Calculator", new Button.ClickListener(){
public void buttonClick(Button.ClickEvent event){
Notification.show(messages.getMessage("first"));
}
});
return button;
}
private CalculatorViewImpl calculator() {
CalculatorModel model = new CalculatorModel();
CalculatorViewImpl view = new CalculatorViewImpl();
new CalculatorPresenter(model, view);
return view;
}
}