一般可以分为
@Controller @Service @Repository -- 都写成@Component也可以
Rest接口可以用
@Component
@Resource 是属于JDK的,一般不用
各个层之间用
@Autowired 来注入 -- 单例的
事务可以在方法前 或是类前用 -- 比原来的tx:advice aop:config方便很多
@Transactional
在配置文件中
读取properties文件
POM中的plugin指定 JJE_CONFIG_HOME
<systemProperty>
<name>JJE_CONFIG_HOME</name>
<value>src/main/resources</value>
</systemProperty>
@Controller @Service @Repository -- 都写成@Component也可以
Rest接口可以用
@Component
@Resource 是属于JDK的,一般不用
各个层之间用
@Autowired 来注入 -- 单例的
事务可以在方法前 或是类前用 -- 比原来的tx:advice aop:config方便很多
@Transactional
在配置文件中
<context:annotation-config />
<context:component-scan base-package="com.jje" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
读取properties文件
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="1"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>file:${JJE_CONFIG_HOME}/vbp.properties</value>
</list>
</property>
</bean>
@Value(value="${lottery.startDate}")
private String startDate;
@Value(value="${lottery.endDate}")
private String endDate;
POM中的plugin指定 JJE_CONFIG_HOME
<systemProperty>
<name>JJE_CONFIG_HOME</name>
<value>src/main/resources</value>
</systemProperty>
本文详细介绍了Spring框架中的核心注解使用方法,包括组件扫描、事务管理、属性注入等,并展示了如何通过配置文件加载外部属性。
167万+

被折叠的 条评论
为什么被折叠?



