Guest User

Untitled

a guest
Apr 26th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. org.springframework.context.support.AbstractApplicationContext prepareRefresh
  2. INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@369f73a2: startup date [Thu Apr 26 18:53:49 MSK 2018]; root of context hierarchy
  3. апр. 26, 2018 6:53:49 ПП org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  4. INFO: Loading XML bean definitions from class path resource [context.xml]
  5. Exception in thread "main" java.lang.NullPointerException
  6. at ru.javabegin.training.spring.aop.SpelConfig.Collectionss.DoSomething(Collectionss.java:24)
  7. at ru.javabegin.training.spring.aop.main.Start.main(Start.java:16)
  8.  
  9. public class Start {
  10.  
  11. public static void main(String[] args) {
  12.  
  13. ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
  14.  
  15. Collectionss collectionss=(Collectionss)context.getBean("collect");
  16.  
  17. collectionss.DoSomething();
  18.  
  19. }
  20.  
  21.  
  22. }
  23.  
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27. xmlns:context="http://www.springframework.org/schema/context"
  28. xmlns:util="http://www.springframework.org/schema/util"
  29. xsi:schemaLocation="
  30. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  31. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  32. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
  33.  
  34.  
  35. <context:component-scan base-package="ru.javabegin.training.*"/>
  36. <context:annotation-config/>
  37.  
  38.  
  39. <util:list id="testList1">
  40. <value>4</value>
  41. <value>5</value>
  42.  
  43. </util:list>
  44.  
  45. <util:list id="testList2">
  46. <value>6</value>
  47. <value>7</value>
  48. </util:list>
  49.  
  50.  
  51. </beans>
  52.  
  53. package ru.javabegin.training.spring.aop.SpelConfig;
  54.  
  55. import org.springframework.stereotype.Service;
  56. import javax.annotation.Resource;
  57. import java.util.List;
  58.  
  59. @Service("collect")
  60. public class Collectionss {
  61.  
  62. @Resource(name = "testList2")
  63. private List list;
  64.  
  65.  
  66. public List getList() {
  67. return list;
  68. }
  69.  
  70. public void setList(List list) {
  71. this.list = list;
  72. }
  73.  
  74. public void DoSomething(){
  75.  
  76. for (Object obj:list
  77. ) {
  78. System.out.println("List: "+ obj );
  79.  
  80. }
  81.  
  82. }
  83. }
Add Comment
Please, Sign In to add comment