springmvc使用excel模板导出

时间:2013-04-26 12:52:43

标签: spring excel

代码运行良好,但是当我setUrl在Excel中使用我的模板时,我收到此错误:

  

ApplicationObjectSupport实例[key.kotori.sms.utils.reports.StockReportsExcel:unnamed]不在ApplicationContext'中运行。

public class StockReportsExcel extends AbstractExcelView {

    private StockReports reports;

    public StockReportsExcel(StockReports reports) {
        this.reports = reports;
        //super.setUrl("report/stock.xls");
    }

    @Override
    protected void buildExcelDocument(
        Map<String, Object> model,
        HSSFWorkbook workbook, 
        HttpServletRequest request,
        HttpServletResponse response) throws Exception {
            workbook.createSheet().createRow(0).createCell(0).setCellValue("kotori");       
            RequestEncoding.encoding(request, response, "test.xls");
            response.setContentType("application/vnd.ms-excel");
        }
    }

    Controller

    @RequestMapping("/excel.do")
    public View excel(Params params) {
        StockReports reports = this.stockReportService.reports(params);
        StockReportsExcel excel = new StockReportsExcel(reports);
        return excel;
    }

我没有在applicationContext.xml中设置任何ViewResolver。 appicationContext.xml中有什么我缺少的吗?

这是applicationContext.xml文件。

 <context:component-scan base-package="key.kotori.sms"></context:component-scan>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/sms"/>
    <property name="username" value="root"/>
    <property name="password" value="admin"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="mappingDirectoryLocations">
        <list>
            <value>classpath:key/kotori/sms/entity</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <value>
            hibernate.dialect=org.hibernate.dialect.MySQLDialect
            hibernate.show_sql=true
            hibernate.format_sql=true
        </value>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<tx:advice id="txAdivce" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="get" read-only="true" />
        <tx:method name="list*" read-only="true" />
        <tx:method name="*" />
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:advisor advice-ref="txAdivce" pointcut="execution(* key.kotori.sms.service.*.*(..))" />
</aop:config>

0 个答案:

没有答案
相关问题