At the beginning, the servcie of the action was not annotated successfully, and a null pointer error was reported. Finally, the method in Dao and service was annotated to find that the annotation was successful, however, the action's servcie is still empty and has not been annotated as Al. Finally, I checked the token from the Internet:
Mybatis-spring-1.1.1
Partial configuration of application. xml
<Context: annotation-config/>
<Context: component-scan base-package = "com. mypojo"> </Context: component-scan>
<Bean id = "datasource" class = "org. logicalcobwebs. proxool. proxooldatasource">
<Property name = "driver" value = "com. Microsoft. JDBC. sqlserver. sqlserverdriver"/>
<Property name = "driverurl" value = "JDBC: sqlserver: // 192.168.4.114: 1433; databasename = userlogin"/>
<Property name = "user" value = "SQL"/>
<Property name = "password" value = "123456"/>
<Property name = "maximumactivetime" value = "18000000"/>
<Property name = "maximumconnectioncount" value = "20"/>
<Property name = "minimumconnectioncount" value = "1"/>
<Property name = "prototypecount" value = "5"/>
<Property name = "housekeepingsleeptime" value = "60000"/>
</Bean>
<! -- Configure the datesource manager -->
<Bean id = "transactionmanager" class = "org. springframework. JDBC. datasource. cetcetransactionmanager">
<Property name = "datasource" ref = "datasource"> </property>
</Bean>
<! -- Integrate myibatis -->
<Bean id = "sqlsessionfactory" class = "org. mybatis. Spring. sqlsessionfactorybean">
<Property name = "configlocation" value = "classpath:/config/mybatis/mybatis-config.xml">
</Property>
<Property name = "datasource" ref = "datasource"> </property>
</Bean>
<Bean id = "sqlsessiontemplate" class = "org. mybatis. Spring. sqlsessiontemplate">
<Constructor-Arg name = "sqlsessionfactory" ref = "sqlsessionfactory"/>
</Bean>
DAO implementation class
@ Repository
Public class studaoimp implements studao {
// @ Autowired
Private sqlsessiontemplate;
Public sqlsessiontemplate getsqlsessiontemplate (){
Return sqlsessiontemplate;
}
@ Resource
Public void setsqlsessiontemplate (sqlsessiontemplate ){
System. Out. println ("injected Ah set sqlsessiontemplate success ");
This. sqlsessiontemplate = sqlsessiontemplate;
}
Implementation class at the Business Layer
@ Service ("stuservice ")
Public class stuserviceimp implements stuservice {
Private studao;
Public studao getstudao (){
Return studao;
}
@ Autowired
Public void setstudao (studao ){
System. Out. println ("annotated stuservice ");
This. studao = studao;
If (this. studao = NULL)
{
System. Out. println ("annotation stuservice failed, it is empty ");
}
Else
{
System. Out. println ("stuservice annotation succeeded, not empty ");
}
}
Action
@ Parentpackage ("struts-Default ")
// @ Namespace ("/user ")
@ Controller
@ Scope ("prototype ")
Public class studentaction extends actionsupport {
/**
*
*/
Private Static final long serialversionuid = 1l;
@ Autowired
Private stuservice;
Public stuservice getstuservice (){
Return stuservice;
}
@ Resource (name = "stuservice ")
Public void setstuservice (stuservice ){
System. Out. println ("annotated stuaction ");
This. stuservice = stuservice;
}