Home > Back-end >  Excuse me for SpringMVC @ the @autowired of Controller cannot automatic injection, the object is nul
Excuse me for SpringMVC @ the @autowired of Controller cannot automatic injection, the object is nul

Time:03-30


web, XML
 

SpringDispatcherServlet
Org. Springframework. Web. Servlet. DispatcherServlet


ContextConfigLocation
The classpath: com/Java/bean/for SpringMVC xml


1 & lt;/load - on - startup>



SpringDispatcherServlet
/& lt;/url - pattern>




for SpringMVC. XML
 













DAO layer
 @ Repository 
Public class BookDAOImpl implements BookDAO {

The @autowired
private JdbcTemplate jdbcTemplate;

@ Override
The method of add delete
}



the service layer
 @ Service 
Public class BookServiceImpl implements BookService {

The @autowired
Private BookDAO BookDAO;

@ Override
The method of add delete

}

JDBC + BookDAOImpl + BookServiceImpl Test normal, add and delete can use
But an error occurred when the Controller, the @autowired can't automatic injection
Controller
 @ Controller 
Public class bookController {

The @autowired
Private BookDAO BookDAO;

@ RequestMapping (value="https://bbs.csdn.net/page/book/list_book")
Public String listBook Model (Model) {
List Booklist=bookDAO. Query ();
Model. The addAttribute (" list ", booklist);
Return "../manage/book_manage. JSP ";
}

}


the index page
 & lt; A href="https://bbs.csdn.net/topics/list_book" & gt; The book management & lt;/a> 


book_manage page
 & lt; H1 & gt; List & lt;/h1 & gt; 

Id
Name



${list. Id} & lt;/td>
The ${list. The name} & lt;/td>




Click on an error after the book management, error message:
Org. Apache. Jasper. JasperException: An exception occurred processing JSP page/page/manage/book_manage JSP at line 32

29:
30: & lt; C: forEach items="${list}" var="book" & gt;
31: & lt; Tr>
32: & lt; Td> ${list. Id} & lt;/td>
33: & lt; Td> The ${list. The name} & lt;/td>

Tried bookController class to remove traversal functions, can be normal jump
Try the output booklist, error Java. Lang. NullPointerException: always invoke a "com. Book. DAO. BookDAO. Query ()" because ". This BookDAO "is null


  • Related