jar文件中的Java类未被扫描

时间:2012-06-24 14:41:32

标签: spring

在spring + spring orm hibernate项目中,我有包含orm配置xml和pojos以及DAO类的dao层的独立jar,我有同名的pojo类,但在我的web-app中用于表示层的其他包中。

问题是,在服务器启动时,LocalSessionFactoryBean正在尝试映射来自web-inf classes文件夹的类,而不是jar文件。这个jar文件在web-inf / lib下,使用tomcat 7。

有什么建议吗?

E.g。 zipCode在com.mycomp.xyz.domainObject.Address中。 但是没有表示层对象com.mycomp.xyz.vo.Address

以下是例外:

Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for zipCode in class com.mycomp.xyz.domainObject.Address
    at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
    at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
    at org.hibernate.mapping.Property.getGetter(Property.java:272)

使用spring-hibernate3-2.0.7.jar和spring-orm-3.1.1.RELEASE。

配置:

<context:annotation-config />
<context:component-scan base-package="com.mycomp.xyz" />

<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:configuration.properties</value>
        </list>
    </property>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driver.className}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>


<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
        <list>
            <value>hibernate/Address.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${jdbc.hibernate.dialect}</prop>
        </props>            
    </property>
</bean>

Address.hbm.xml

<class name="com.mycomp.xyz.domainObject.Address" table="tbl_address">
    <id name="id" type="long" column="id">
        <generator class="native" />
    </id>

    <property name="addressLine1" type="string">
        <column name="address_line1" />
    </property>
    <property name="addressLine2" type="string">
        <column name="address_line2" />
    </property>
    <property name="city" type="string">
        <column name="city" />
    </property>
    <property name="state" type="string">
        <column name="state" />
    </property>
    <property name="country" type="string">
        <column name="country" />
    </property>
    <property name="zipCode" type="string">
        <column name="zip_code" />
    </property>
    <property name="addressType" type="string">
        <column name="address_type" />
    </property>
</class>

JAVA:com.mycomp.xyz.domainObject.Address

公共类地址{

private long id;
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String zipCode;
private String addressType;
    private String country;

public String getAddressType() {
    return addressType;
}   
public void setAddressType(String addressType) {
    this.addressType = addressType;
}
public String getZipCode() {
    return zipCode;
}   
public void setZipCode(String zipCode) {
    this.zipCode = zipCode;
}   
public long getId() {
    return id;
}   
public void setId(long id) {
    this.id = id;
}   
public String getAddressLine1() {
    return addressLine1;
}   
public void setAddressLine1(String addressLine1) {
    this.addressLine1 = addressLine1;
}   
public String getAddressLine2() {
    return addressLine2;
}   
public void setAddressLine2(String addressLine2) {
    this.addressLine2 = addressLine2;
}   
public String getCity() {
    return city;
}
public void setCity(String city) {
    this.city = city;
}
public String getState() {
    return state;
}   
public void setState(String state) {
    this.state = state;
}   
public String getCountry() {
    return country;
}   
public void setCountry(String country) {
    this.country = country;
}

}

**

  

以上所有内容都在带有DAO的jar中。

**

JAVA:com.mycomp.xyz.vo.Address 这是在网络应用中

公共类地址{

private long id;
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String pinCode;
private String country;

public final long getId() {
    return id;
}
public final void setId(long id) {
    this.id = id;
}
public final String getAddressLine1() {
    return addressLine1;
}
public final void setAddressLine1(String addressLine1) {
    this.addressLine1 = addressLine1;
}
public final String getAddressLine2() {
    return addressLine2;
}
public final void setAddressLine2(String addressLine2) {
    this.addressLine2 = addressLine2;
}
public final String getCity() {
    return city;
}
public final void setCity(String city) {
    this.city = city;
}
public final String getState() {
    return state;
}
public final void setState(String state) {
    this.state = state;
}
public final String getPinCode() {
    return pinCode;
}
public final void setPinCode(String pinCode) {
    this.pinCode = pinCode;
}
public final String getCountry() {
    return country;
}
public final void setCountry(String country) {
    this.country = country;
}

}

0 个答案:

没有答案