Struts2 + mybatis3.1 + spring3.0 annotation the servcie with the action configured is not successfully Annotated

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.