试图使用在intellij中工作的spring mybatis项目获得样本petstore

时间:2013-12-06 19:26:48

标签: intellij-idea

我已从http://mybatis.github.io/spring/sample.html下载了示例。

1)然后我打开pom.xml并将其导入intellij

2)我添加了一个弹簧MVC方面

3)我添加了一个web facet

4)我正在使用intellij 12.1.6

完成后,自动装配失败。我正在努力学习这个新框架

所有服务autowires都有类似于::的错误         无法自动装配。找不到'LineItemMapper'类型的bean

 public class OrderService {
   @Autowired
 private ItemMapper itemMapper;
   @Autowired
 private OrderMapper orderMapper;
   @Autowired
 private SequenceMapper sequenceMapper;
   @Autowired
 private LineItemMapper lineItemMapper;

我认为这是我在项目中设置错误的原因。

这是示例中提供的applicationCOntext

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:jdbc="http://www.springframework.org/schema/jdbc"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans   
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc     
     http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
     http://www.springframework.org/schema/tx   
     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
     http://www.springframework.org/schema/aop   
     http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

     <!-- in-memory database and a datasource -->
     <jdbc:embedded-database id="dataSource">
        <jdbc:script location="classpath:database/jpetstore-hsqldb-schema.sql"/>
        <jdbc:script location="classpath:database/jpetstore-hsqldb-dataload.sql"/>
     </jdbc:embedded-database>

     <!-- transaction manager, use JtaTransactionManager for global tx -->
     <bean id="transactionManager"     
         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
         <property name="dataSource" ref="dataSource" />
     </bean>

<!-- enable component scanning (beware that this does not enable mapper scanning!) -->    
<context:component-scan base-package="org.mybatis.jpetstore.service" />

<!-- enable autowire -->
<context:annotation-config />

<!-- enable transaction demarcation with annotations -->
<tx:annotation-driven />

<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="typeAliasesPackage" value="org.mybatis.jpetstore.domain" />
</bean>

<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="org.mybatis.jpetstore.persistence" />
</bean>

</beans>

这是项目https://www.dropbox.com/s/lohr3udnm0oa2hn/mybatis-jpetstore-6.0.1-sources.zip

的拉链

希望有人可以指出我做错了什么 谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

首先要做的是尝试使用本周早些时候发布的最新版本的IntelliJ。它改善了对弹簧的支持。

潜在的问题是你需要设置IntelliJ的spring facet并分配应用程序上下文组。