1

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

ApplicationObjectSupport 实例 [key.kotori.sms.utils.reports.StockReportsExcel:未命名] 不在 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>
4

0 回答 0