2017-06-05 80 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'本身,而不是工厂的返回对象(我希望听起来很清楚;) –

相关问题