1

Мое имя Daniel и я новичок Java и WebApplications. У меня вопрос, потому что у меня проблема с NullPointerException.Spring DI NullPointerException @Autowired fail

Я изучаю инъекцию зависимой от весны. Я сделал ошибку, но не могу ее найти. Благодарим вас за помощь.

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.sp[email protected]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.spring[email protected]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.spring[email protected]2a521c9d: org.s[email protected]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 [[email protected]e86e] 
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.[email protected]7c485f83] 
16:05:11.009 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in org.s[email protected]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 [[email protected]c62d60] 
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

пожалуйста post полный стек следы. Это поможет с точным указанием выводов. Также аннотацию '@ Component' следует применять к классу, а не по интерфейсу –

+0

Любой может помочь? – danieloo

+0

Очевидно, что в вашем классе 'HelpView' (первый внутренний класс) произошла ошибка из-за этой строки стека ошибок:' pl.infotower.views.HelpView $ 1.buttonClick (HelpView.java:52) '. Не могли бы вы показать нам код этого класса, особенно все, что касается линии 52? –

ответ

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; 
    } 

} 
1

Vaadin объекты изначально не управляется Spring контейнером. Поэтому аннотация @Autowired, используемая в классе HelpView, не выполняется. Чтобы привести пример в работу, вам нужно сделать некоторые интеграционные усилия. Есть несколько различных подходов, которые можно найти в блогах и учебниках в Интернете.

Один из подходов, работающих, не меняя ваш пример кода на много, использует @AspectJ. Я объясню это с помощью Maven как инструмента управления. Пожалуйста, примите необходимые шаги, если вы управляете своим проектом по-другому.

Главная точка: аннотировать классы Vaadin (или любые другие не пружинные классы), а также нуждающихся в возможности автоматического связывания/впрыска с @Configurable. Не забудьте добавить запись <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 на ваш pom.xml, как ребенка <plugins />):

 <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 RESSOURCES необходимы. Скопируйте следующие строки в 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, корневой context.xml, applicationContext.xml, или независимо от имени вашего 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 /> 

Версия номер версий я выбрал работу в моей среде вместе хорошо.Возможно, нужно изменить их соответственно своей среде.

Смежные вопросы