我正在开发一个应用程序,它有两个(Spring)应用程序上下文配置,一个来自Java class
,另一个来自xml
文件(commonApplicationContext
。xml
)。
Java类配置 - >
@Configuration
@PropertySource("classpath:apis.application.properties")
/*
* The component scan can be used to add packages and exclusions to the default
* package
*/
@ComponentScan(basePackages = {"org.surfnet.oaaas.resource", "org.surfnet.oaaas.service"})
@ImportResource("classpath:spring-repositories.xml")
@EnableTransactionManagement
public class SpringConfiguration {
}
XML配置(commonApplicationContext.xml) - >
<context:component-scan base-package="com.test.common.dao.*,org.surfnet.*">
<context:exclude-filter type="regex" expression="org\.surfnet\.*"/>
</context:component-scan>
<context:annotation-config />
<!--tx:annotation-driven transaction-manager="defaultTransactionManager"/-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="common"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="packagesToScan" value="com.test.common.dao.entity"/>
<!--property name="jpaVendorAdapter" ref="jpaVendorAdapter"/-->
</bean>
<!--<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="database" value="MYSQL"/>
</bean>-->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
现在我想知道有没有办法在web.xml中加载这两个配置?我在下面试过,但没有工作
web.xml条目 - &gt;
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
org.surfnet.oaaas.config.SpringConfiguration
classpath:commonApplicationContext.xml
</param-value>
</context-param>
答案 0 :(得分:0)
加载注释配置上下文就足够了,因为它导入了XML上下文