1

util我正在尝试构建一个使用 Apache Camel HL7 和 Spring JPA 的简单应用程序。目前我的 Spring JPA 配置是通过 ApplicationContext 类完成的。Camel 正在通过 xml 进行配置。我的 web.xml 如下:

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Fusion Core HL7 Consumer</display-name>

<!-- location of spring xml files -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-config.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>CamelServlet</servlet-name>
    <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>CamelServlet</servlet-name>
    <url-pattern>/camel/*</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>util.Startup</listener-class>
</listener>

和spring-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

        <import resource="camel-config.xml"/>
        <!--  import resource="jpa-config.xml"/ -->
</beans>

和 ApplicationContext 的一部分:

@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = { "au.com.incarta.fusion.core.repository" })
@PropertySource("classpath:application.properties")
@EnableJpaRepositories("au.com.incarta.fusion.core.repository")
public class ApplicationContext {

我不确定如何正确加载 ApplicationContext 类。我很可能完全感到困惑,并且有更好的方法来做这一切!

4

1 回答 1

1

ApplicationContext 使用@Configuration 进行注释。

如果您将以下内容添加到 spring-config.xml 中,Spring 只会检测到这一点

<context:component-scan base-package="<your base package>" />
于 2014-12-20T18:38:27.510 回答