2017-06-05 79 views
0

我正在使用駱駝藍圖並面臨着hibernate組件的問題。 這個例子在春季,但沒有藍圖工作正常JBoss的保險絲6.3V,Camel-Blueprint無法將值org.springframework.orm.hibernate4.LocalSessionFactoryBean轉換爲類型org.hibernate.SessionFactory

所提供的例子是在春季和工作正常,但在藍圖任何例子將有助於 http://camel.apache.org/hibernate-example.html

錯誤: org.osgi .service.blueprint.container.ComponentDefinitionException:錯誤設置屬性:PropertyDescriptor引起:java.lang.Exception:無法將值[email protected]063轉換爲在org.apache處鍵入org.hibernate.SessionFactory .aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:184)

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> 
    <bean class="org.apache.commons.dbcp.BasicDataSource" 
     destroy-method="close" id="dataSource"> 
     <property name="url" 
      value="jdbc:sqlserver://x:1433;DatabaseName=x" /> 
     <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /> 
     <property name="username" value="" /> 
     <property name="password" value="" /> 
     <property name="removeAbandoned" value="true" /> 
     <property name="initialSize" value="20" /> 
     <property name="maxActive" value="30" /> 
    </bean> 
    <bean class="com.x.dto.ReferenceTable" id="refBean" /> 
    <!-- <bean class="com.x.dao.ReferenceDAOImpl" id="MyBean"> 
     <property name="sessionFactory" ref="mysessionFactory" /> 
    </bean> --> 

    <!-- setup the Camel hibernate component --> 
    <bean class="org.apacheextras.camel.component.hibernate.HibernateComponent" 
     id="hibernate"> 
     <property name="sessionFactory" ref="mysessionFactory" /> 
    </bean> 

    <bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" 
     id="mysessionFactory"> 
     <property name="dataSource" ref="dataSource" /> 
     <!-- here we define the hibernate mapping files we use --> 
     <property name="packagesToScan"> 
      <list> 
       <value>com.x.dto</value> 
      </list> 
     </property> 
     <property name="annotatedClasses"> 
      <list> 
       <value>com.x.dto.ReferenceTable</value> 
      </list> 
     </property> 
     <!-- and here we have additional hibernate options --> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> 
       <prop key="hibernate.show_sql">true</prop> 
      </props> 
     </property> 
    </bean> 
    <camelContext id="_context1" 
     xmlns="http://camel.apache.org/schema/blueprint"> 
     <route id="_route1"> 
      <from id="from" uri="hibernate://com.x.dto.ReferenceTable?consumer.query=select x.data from com.x.dto.ReferenceTable x where x.id='id3'"/> 
      <!-- <bean id="_bean1" method="save(com.x.dto.ReferenceTable)" ref="MyBean"/> 
      <bean id="_bean2" method="getByID('id2')" ref="MyBean"/> 
      <convertBodyTo id="_convertBodyTo1" type="com.x.dto.ReferenceTable"/> --> 
      <to id="_to1" uri="log: ${body}"/> 
     </route> 
    </camelContext> 
</blueprint> 

pom.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<project 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.mycompany</groupId> 
    <artifactId>camel-blueprint</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>bundle</packaging> 
    <name>Camel Blueprint Quickstart</name> 
    <description>Empty Camel Blueprint Example</description> 
    <licenses> 
     <license> 
      <name>Apache License, Version 2.0</name> 
      <url>http://www.apache.org/licenses/LICENSE-2.0.html</url> 
      <distribution>repo</distribution> 
     </license> 
    </licenses> 
    <properties> 
     <camel.version>2.17.0.redhat-630187</camel.version> 
     <version.maven-bundle-plugin>3.2.0</version.maven-bundle-plugin> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <jboss.fuse.bom.version>6.3.0.redhat-187</jboss.fuse.bom.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.jboss.fuse.bom</groupId> 
       <artifactId>jboss-fuse-parent</artifactId> 
       <version>${jboss.fuse.bom.version}</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.apache.camel</groupId> 
      <artifactId>camel-core</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.camel</groupId> 
      <artifactId>camel-blueprint</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.camel</groupId> 
      <artifactId>camel-test-blueprint</artifactId> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>commons-dbcp</groupId> 
      <artifactId>commons-dbcp</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>com.microsoft.sqlserver</groupId> 
      <artifactId>mssql-jdbc</artifactId> 
      <version>6.1.0.jre8</version> 
     </dependency> 
     <dependency> 
     <groupId>org.apache-extras.camel-extra</groupId> 
     <artifactId>camel-hibernate</artifactId> 
     <version>2.15.0</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
    </dependency> 

    </dependencies> 
    <repositories> 
     <repository> 
      <releases> 
       <enabled>true</enabled> 
       <updatePolicy>never</updatePolicy> 
      </releases> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
      <id>fuse-public-repository</id> 
      <name>FuseSource Community Release Repository</name> 
      <url>https://repo.fusesource.com/nexus/content/groups/public</url> 
     </repository> 
     <repository> 
      <releases> 
       <enabled>true</enabled> 
       <updatePolicy>never</updatePolicy> 
      </releases> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
      <id>red-hat-ga-repository</id> 
      <name>Red Hat GA Repository</name> 
      <url>https://maven.repository.redhat.com/ga</url> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <releases> 
       <enabled>true</enabled> 
       <updatePolicy>never</updatePolicy> 
      </releases> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
      <id>fuse-public-repository</id> 
      <name>FuseSource Community Release Repository</name> 
      <url>https://repo.fusesource.com/nexus/content/groups/public</url> 
     </pluginRepository> 
     <pluginRepository> 
      <releases> 
       <enabled>true</enabled> 
       <updatePolicy>never</updatePolicy> 
      </releases> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
      <id>red-hat-ga-repository</id> 
      <name>Red Hat GA Repository</name> 
      <url>https://maven.repository.redhat.com/ga</url> 
     </pluginRepository> 
    </pluginRepositories> 
    <build> 
     <defaultGoal>install</defaultGoal> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-bundle-plugin</artifactId> 
       <version>${version.maven-bundle-plugin}</version> 
       <extensions>true</extensions> 
       <configuration> 
        <instructions> 
         <Bundle-SymbolicName>keyvalue</Bundle-SymbolicName> 
         <Bundle-Name>Empty Camel Blueprint Example [keyvalue]</Bundle-Name> 
        </instructions> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.5.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-resources-plugin</artifactId> 
       <version>3.0.1</version> 
       <configuration> 
        <encoding>UTF-8</encoding> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.camel</groupId> 
       <artifactId>camel-maven-plugin</artifactId> 
       <version>${camel.version}</version> 
       <configuration> 
        <useBlueprint>true</useBlueprint> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

回答

5

記住一兩件事。 org.springframework.orm.hibernate4.LocalSessionFactoryBean是Spring的工廠bean當用作<bean>時,它給你一種間接的方式 - 不是直接使用class作爲bean,而是調用getObject(),返回的對象是你的<bean>

另一件事是Spring爲所有實現了InitializingBean的bean(或工廠bean)自動調用afterPropertiesSet()

所以不是:

<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" 
     id="mysessionFactory"> 

使用:

所有感謝您的答覆的
<bean id="mysessionFactory" factory-ref="mysessionFactoryFactory" 
     factory-method="getObject" /> 

<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" 
     id="mysessionFactoryFactory" init-method="afterPropertiesSet"> 
... 
+0

第一。這是我學到的新東西。上述更改後,我越來越期待org.osgi.service.blueprint.container.ComponentDefinitionException:無法實例化組件:java.lang.NullPointerException \t at org.apache.aries.blueprint.container.BeanRecipe.getInitMethod(BeanRecipe。 java:619) –

+0

對不起 - 我從頭開始寫 - init-method應該添加到id =「mysessionFactoryFactory」的bean,而不是id =「mysessionFactory」的bean,因爲它應該被調用'hibernate4.LocalSessionFactoryBean'本身,而不是工廠的返回對象(我希望聽起來很清楚;) –

相關問題