【问题标题】:Annotation based ApplicationContext基于注解的 ApplicationContext
【发布时间】:2011-09-23 06:09:40
【问题描述】:

我了解 ApplicationContext 可以是基于 Spring 3 的注解。

谁能分享一个例子,我可以参考一下。

提前致谢, 维韦克

编辑 - 这是 XML 配置:

<context:annotation-config /> <context:component-scan base-package="com.test" /> <mvc:annotation-driven /> <bean id="dataSource" destroy-method="close" class=org.apache.commons.dbcp.BasicDataSource "> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test" /> <property name="username" value="test" /> <property name="password" value="test" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="mapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.test.Mapper" /> <property name="sqlSessionFactory" ref="sqlSessionFactory" /> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="dao" class="com.test.MapperDao"> <property name="mapper" ref="mapper" /> </bean> <bean id="Controller" class="com.test.Controller" />

【问题讨论】:

  • 您如何向我们展示您将如何在 XML 中执行此操作,然后我们向您展示 Spring 3 等效项。交易?
  • 当然,这是我的 XML &lt;context:annotation-config /&gt; &lt;context:component-scan base-package="com.test" /&gt; &lt;mvc:annotation-driven /&gt; &lt;bean id="dataSource" destroy-method="close" &lt;class="org.apache.commons.dbcp.BasicDataSource"&gt; &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt; &lt;property name="url" value="jdbc:mysql://localhost:3306/test" /&gt; &lt;property name="username" value="test" /&gt; &lt;property name="password" value="test" /&gt; &lt;/bean&gt; &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;/bean&gt;
  • &lt;bean id="mapper" class="org.mybatis.spring.mapper.MapperFactoryBean"&gt; &lt;property name="mapperInterface" value="com.test.Mapper" /&gt; &lt;property name="sqlSessionFactory" ref="sqlSessionFactory" /&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;/bean&gt; &lt;bean id="dao" class="com.test.MapperDao"&gt; &lt;property name="mapper" ref="mapper" /&gt; &lt;/bean&gt; &lt;bean id="Controller" class="com.test.Controller"/&gt;
  • 对不起....尽力格式化xml...但不知何故它不起作用..

标签: spring annotations


【解决方案1】:

我已经阅读了 Spring 3 文档并理解了 @Configuration 注释。 所以问题解决了:)

【讨论】:

  • 您能否与我们分享您的见解?
猜你喜欢
  • 2015-04-17
  • 1970-01-01
  • 2015-04-17
  • 1970-01-01
  • 2015-04-09
  • 2015-06-25
  • 2014-09-02
  • 2019-01-11
  • 1970-01-01
相关资源
最近更新 更多