Java 自动连线失败:不是托管类型

Java 自动连线失败:不是托管类型,java,spring,spring-mvc,spring-data-jpa,hessian,Java,Spring,Spring Mvc,Spring Data Jpa,Hessian,我的毕业设计有个大问题,如果你们能帮助我,我会非常高兴的! 我做了一个Maven多模块项目,有3个“核心项目” NaviClean:(父级) NaviCleanDomain:包含域模型以及所有我的实体和 NaviCleanServer所需的接口MeinRemoteDienst 和NaviCleanCleint用于Hessianprotocol NaviCleanClient:连接GUI和到的Hessian连接 NaviCleanServer NaviCleanServer:这是我的存储库,我与

我的毕业设计有个大问题,如果你们能帮助我,我会非常高兴的! 我做了一个Maven多模块项目,有3个“核心项目”

  • NaviClean
    :(父级)
  • NaviCleanDomain
    :包含域模型以及所有我的实体和 NaviCleanServer所需的接口
    MeinRemoteDienst
    NaviCleanCleint
    用于
    Hessianprotocol
  • NaviCleanClient
    :连接GUI和到的Hessian连接
    NaviCleanServer
  • NaviCleanServer
    :这是我的存储库,我与数据库的连接 以及接口的实现
    einRemoteDienst
    NaviCleanServer
    NaviCleanClient
    在Maven as中具有
    NaviCleanDomain
    依赖性
现在,每次我尝试在Tomcat上启动服务器时,都会出现以下错误:

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transaktionsRepository': 
Injection of persistence dependencies failed; 
nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: 
Error loading class [at.naviclean.service.impl.MeinRemoteDienstImpl] for bean with name 'meinRemoteDienstImpl' defined in file [C:\Users\Fredy\Documents\workspace-sts-3.1.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\NaviCleanServer\WEB-INF\classes\at\naviclean\service\impl\MeinRemoteDienstImpl.class]: 
problem with class file or dependent class; 
nested exception is java.lang.NoClassDefFoundError: at/naviclean/service/MeinRemoteDienst
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
    ……………….
模型库:

package at.naviclean.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@SuppressWarnings("serial")
@MappedSuperclass
public class ModelBase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Version
    @Column(name = "ts")
    private Date timestamp;

    public Long getId() {
        return id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

}
package at.naviclean.domain;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Kassa extends ModelBase {

    @Column(name = "name", unique = true)
    private String name;

    @Column(name = "geld")
    private int geld;

    public Kassa(String name, int geld) {
        this.name = name;
        this.geld = geld;
    }

    public Kassa() {
    }

    public String getName() {
        return name;
    }

    public int getGeld() {
        return geld;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGeld(int geld) {
        this.geld = geld;
    }

}
package at.naviclean.service;

import at.naviclean.domain.Kassa;

public interface MeinRemoteDienst {

    int getKassaCount(int plus);

    String getNameFromKassa(int id);

    Kassa findById(int id);
}
package at.naviclean.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import at.naviclean.domain.Kassa;

public interface KassaRepository extends BaseRepository<Kassa> {
    List<Kassa> findByGeld(int geld);

    Kassa findByName(String name);

    @Query("select k from Kassa k where k.geld = ?1")
    Kassa findByGeld1(int geld);
}
package at.naviclean.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import at.naviclean.domain.Kassa;
import at.naviclean.repositories.KassaRepository;
import at.naviclean.service.MeinRemoteDienst;

@Service
public class MeinRemoteDienstImpl implements MeinRemoteDienst {

    @Autowired(required = true)
    public KassaRepository kassaR;

    public int getKassaCount(int plus) {
        return 2;
    }


    public String getNameFromKassa(int id) {
        return kassaR.findById(id + 0l).getName();
    }

    @Override
    public Kassa findById(int id) {
        return = kassaR.findById(id + 0l);
    }

}
<?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:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <import resource="infrastructures.xml" />

    <jpa:repositories base-package="at.naviclean.repositories">
        <repository:exclude-filter type="regex"
            expression="at.naviclean.repositories.BaseRepository" />
    </jpa:repositories>

    <context:component-scan base-package="at.naviclean.service.impl" />

</beans>
<?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:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">



        <bean id="entityManagerFactory"
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="dataSource" />
                <property name="jpaVendorAdapter">
                        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                <property name="showSql" value="true" />
                                <property name="generateDdl" value="true" />
                                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
                        </bean>
                </property>
        </bean>

        <bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/kassatest" />
                <property name="username" value="root" />
                <property name="password" value="" />
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>


        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

</beans>
<?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:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



<import resource="../root-context.xml" />
    <bean id="idMeinRemoteDienst" class="at.naviclean.service.impl.MeinRemoteDienstImpl" />
    <bean name="/MeinRemoteDienstHessian"
        class="org.springframework.remoting.caucho.HessianServiceExporter"
        p:serviceInterface="at.naviclean.service.MeinRemoteDienst"
        p:service-ref="idMeinRemoteDienst" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="classpath:META-INF/spring/application-context.xml" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>

</web-app>
Kassa:

package at.naviclean.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@SuppressWarnings("serial")
@MappedSuperclass
public class ModelBase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Version
    @Column(name = "ts")
    private Date timestamp;

    public Long getId() {
        return id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

}
package at.naviclean.domain;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Kassa extends ModelBase {

    @Column(name = "name", unique = true)
    private String name;

    @Column(name = "geld")
    private int geld;

    public Kassa(String name, int geld) {
        this.name = name;
        this.geld = geld;
    }

    public Kassa() {
    }

    public String getName() {
        return name;
    }

    public int getGeld() {
        return geld;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGeld(int geld) {
        this.geld = geld;
    }

}
package at.naviclean.service;

import at.naviclean.domain.Kassa;

public interface MeinRemoteDienst {

    int getKassaCount(int plus);

    String getNameFromKassa(int id);

    Kassa findById(int id);
}
package at.naviclean.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import at.naviclean.domain.Kassa;

public interface KassaRepository extends BaseRepository<Kassa> {
    List<Kassa> findByGeld(int geld);

    Kassa findByName(String name);

    @Query("select k from Kassa k where k.geld = ?1")
    Kassa findByGeld1(int geld);
}
package at.naviclean.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import at.naviclean.domain.Kassa;
import at.naviclean.repositories.KassaRepository;
import at.naviclean.service.MeinRemoteDienst;

@Service
public class MeinRemoteDienstImpl implements MeinRemoteDienst {

    @Autowired(required = true)
    public KassaRepository kassaR;

    public int getKassaCount(int plus) {
        return 2;
    }


    public String getNameFromKassa(int id) {
        return kassaR.findById(id + 0l).getName();
    }

    @Override
    public Kassa findById(int id) {
        return = kassaR.findById(id + 0l);
    }

}
<?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:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <import resource="infrastructures.xml" />

    <jpa:repositories base-package="at.naviclean.repositories">
        <repository:exclude-filter type="regex"
            expression="at.naviclean.repositories.BaseRepository" />
    </jpa:repositories>

    <context:component-scan base-package="at.naviclean.service.impl" />

</beans>
<?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:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">



        <bean id="entityManagerFactory"
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="dataSource" />
                <property name="jpaVendorAdapter">
                        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                <property name="showSql" value="true" />
                                <property name="generateDdl" value="true" />
                                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
                        </bean>
                </property>
        </bean>

        <bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/kassatest" />
                <property name="username" value="root" />
                <property name="password" value="" />
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>


        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

</beans>
<?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:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



<import resource="../root-context.xml" />
    <bean id="idMeinRemoteDienst" class="at.naviclean.service.impl.MeinRemoteDienstImpl" />
    <bean name="/MeinRemoteDienstHessian"
        class="org.springframework.remoting.caucho.HessianServiceExporter"
        p:serviceInterface="at.naviclean.service.MeinRemoteDienst"
        p:service-ref="idMeinRemoteDienst" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="classpath:META-INF/spring/application-context.xml" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>

</web-app>
MeinRemoteDienst:

package at.naviclean.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@SuppressWarnings("serial")
@MappedSuperclass
public class ModelBase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Version
    @Column(name = "ts")
    private Date timestamp;

    public Long getId() {
        return id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

}
package at.naviclean.domain;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Kassa extends ModelBase {

    @Column(name = "name", unique = true)
    private String name;

    @Column(name = "geld")
    private int geld;

    public Kassa(String name, int geld) {
        this.name = name;
        this.geld = geld;
    }

    public Kassa() {
    }

    public String getName() {
        return name;
    }

    public int getGeld() {
        return geld;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGeld(int geld) {
        this.geld = geld;
    }

}
package at.naviclean.service;

import at.naviclean.domain.Kassa;

public interface MeinRemoteDienst {

    int getKassaCount(int plus);

    String getNameFromKassa(int id);

    Kassa findById(int id);
}
package at.naviclean.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import at.naviclean.domain.Kassa;

public interface KassaRepository extends BaseRepository<Kassa> {
    List<Kassa> findByGeld(int geld);

    Kassa findByName(String name);

    @Query("select k from Kassa k where k.geld = ?1")
    Kassa findByGeld1(int geld);
}
package at.naviclean.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import at.naviclean.domain.Kassa;
import at.naviclean.repositories.KassaRepository;
import at.naviclean.service.MeinRemoteDienst;

@Service
public class MeinRemoteDienstImpl implements MeinRemoteDienst {

    @Autowired(required = true)
    public KassaRepository kassaR;

    public int getKassaCount(int plus) {
        return 2;
    }


    public String getNameFromKassa(int id) {
        return kassaR.findById(id + 0l).getName();
    }

    @Override
    public Kassa findById(int id) {
        return = kassaR.findById(id + 0l);
    }

}
<?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:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <import resource="infrastructures.xml" />

    <jpa:repositories base-package="at.naviclean.repositories">
        <repository:exclude-filter type="regex"
            expression="at.naviclean.repositories.BaseRepository" />
    </jpa:repositories>

    <context:component-scan base-package="at.naviclean.service.impl" />

</beans>
<?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:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">



        <bean id="entityManagerFactory"
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="dataSource" />
                <property name="jpaVendorAdapter">
                        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                <property name="showSql" value="true" />
                                <property name="generateDdl" value="true" />
                                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
                        </bean>
                </property>
        </bean>

        <bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/kassatest" />
                <property name="username" value="root" />
                <property name="password" value="" />
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>


        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

</beans>
<?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:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



<import resource="../root-context.xml" />
    <bean id="idMeinRemoteDienst" class="at.naviclean.service.impl.MeinRemoteDienstImpl" />
    <bean name="/MeinRemoteDienstHessian"
        class="org.springframework.remoting.caucho.HessianServiceExporter"
        p:serviceInterface="at.naviclean.service.MeinRemoteDienst"
        p:service-ref="idMeinRemoteDienst" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="classpath:META-INF/spring/application-context.xml" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>

</web-app>
BaseRepository

package at.naviclean.repositories;

import org.springframework.data.jpa.repository.JpaRepository;

import at.naviclean.domain.ModelBase;

public interface BaseRepository<T extends ModelBase> extends
        JpaRepository<T, Long> {
    T findById(long id);

}
应用程序上下文.xml:

package at.naviclean.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@SuppressWarnings("serial")
@MappedSuperclass
public class ModelBase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Version
    @Column(name = "ts")
    private Date timestamp;

    public Long getId() {
        return id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

}
package at.naviclean.domain;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Kassa extends ModelBase {

    @Column(name = "name", unique = true)
    private String name;

    @Column(name = "geld")
    private int geld;

    public Kassa(String name, int geld) {
        this.name = name;
        this.geld = geld;
    }

    public Kassa() {
    }

    public String getName() {
        return name;
    }

    public int getGeld() {
        return geld;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGeld(int geld) {
        this.geld = geld;
    }

}
package at.naviclean.service;

import at.naviclean.domain.Kassa;

public interface MeinRemoteDienst {

    int getKassaCount(int plus);

    String getNameFromKassa(int id);

    Kassa findById(int id);
}
package at.naviclean.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import at.naviclean.domain.Kassa;

public interface KassaRepository extends BaseRepository<Kassa> {
    List<Kassa> findByGeld(int geld);

    Kassa findByName(String name);

    @Query("select k from Kassa k where k.geld = ?1")
    Kassa findByGeld1(int geld);
}
package at.naviclean.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import at.naviclean.domain.Kassa;
import at.naviclean.repositories.KassaRepository;
import at.naviclean.service.MeinRemoteDienst;

@Service
public class MeinRemoteDienstImpl implements MeinRemoteDienst {

    @Autowired(required = true)
    public KassaRepository kassaR;

    public int getKassaCount(int plus) {
        return 2;
    }


    public String getNameFromKassa(int id) {
        return kassaR.findById(id + 0l).getName();
    }

    @Override
    public Kassa findById(int id) {
        return = kassaR.findById(id + 0l);
    }

}
<?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:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <import resource="infrastructures.xml" />

    <jpa:repositories base-package="at.naviclean.repositories">
        <repository:exclude-filter type="regex"
            expression="at.naviclean.repositories.BaseRepository" />
    </jpa:repositories>

    <context:component-scan base-package="at.naviclean.service.impl" />

</beans>
<?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:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">



        <bean id="entityManagerFactory"
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="dataSource" />
                <property name="jpaVendorAdapter">
                        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                <property name="showSql" value="true" />
                                <property name="generateDdl" value="true" />
                                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
                        </bean>
                </property>
        </bean>

        <bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/kassatest" />
                <property name="username" value="root" />
                <property name="password" value="" />
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>


        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

</beans>
<?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:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



<import resource="../root-context.xml" />
    <bean id="idMeinRemoteDienst" class="at.naviclean.service.impl.MeinRemoteDienstImpl" />
    <bean name="/MeinRemoteDienstHessian"
        class="org.springframework.remoting.caucho.HessianServiceExporter"
        p:serviceInterface="at.naviclean.service.MeinRemoteDienst"
        p:service-ref="idMeinRemoteDienst" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="classpath:META-INF/spring/application-context.xml" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>

</web-app>
错误:

package at.naviclean.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@SuppressWarnings("serial")
@MappedSuperclass
public class ModelBase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Version
    @Column(name = "ts")
    private Date timestamp;

    public Long getId() {
        return id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

}
package at.naviclean.domain;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Kassa extends ModelBase {

    @Column(name = "name", unique = true)
    private String name;

    @Column(name = "geld")
    private int geld;

    public Kassa(String name, int geld) {
        this.name = name;
        this.geld = geld;
    }

    public Kassa() {
    }

    public String getName() {
        return name;
    }

    public int getGeld() {
        return geld;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGeld(int geld) {
        this.geld = geld;
    }

}
package at.naviclean.service;

import at.naviclean.domain.Kassa;

public interface MeinRemoteDienst {

    int getKassaCount(int plus);

    String getNameFromKassa(int id);

    Kassa findById(int id);
}
package at.naviclean.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import at.naviclean.domain.Kassa;

public interface KassaRepository extends BaseRepository<Kassa> {
    List<Kassa> findByGeld(int geld);

    Kassa findByName(String name);

    @Query("select k from Kassa k where k.geld = ?1")
    Kassa findByGeld1(int geld);
}
package at.naviclean.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import at.naviclean.domain.Kassa;
import at.naviclean.repositories.KassaRepository;
import at.naviclean.service.MeinRemoteDienst;

@Service
public class MeinRemoteDienstImpl implements MeinRemoteDienst {

    @Autowired(required = true)
    public KassaRepository kassaR;

    public int getKassaCount(int plus) {
        return 2;
    }


    public String getNameFromKassa(int id) {
        return kassaR.findById(id + 0l).getName();
    }

    @Override
    public Kassa findById(int id) {
        return = kassaR.findById(id + 0l);
    }

}
<?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:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <import resource="infrastructures.xml" />

    <jpa:repositories base-package="at.naviclean.repositories">
        <repository:exclude-filter type="regex"
            expression="at.naviclean.repositories.BaseRepository" />
    </jpa:repositories>

    <context:component-scan base-package="at.naviclean.service.impl" />

</beans>
<?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:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">



        <bean id="entityManagerFactory"
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="dataSource" />
                <property name="jpaVendorAdapter">
                        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                <property name="showSql" value="true" />
                                <property name="generateDdl" value="true" />
                                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
                        </bean>
                </property>
        </bean>

        <bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/kassatest" />
                <property name="username" value="root" />
                <property name="password" value="" />
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>


        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

</beans>
<?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:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



<import resource="../root-context.xml" />
    <bean id="idMeinRemoteDienst" class="at.naviclean.service.impl.MeinRemoteDienstImpl" />
    <bean name="/MeinRemoteDienstHessian"
        class="org.springframework.remoting.caucho.HessianServiceExporter"
        p:serviceInterface="at.naviclean.service.MeinRemoteDienst"
        p:service-ref="idMeinRemoteDienst" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="classpath:META-INF/spring/application-context.xml" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>

</web-app>
2。我在persistence.xml中手动插入域模型存储库。结果是“绿色”测试,但我仍然无法启动服务器…


提前多谢!!!我无法想象没有您会是什么样子:)

您应该扩展组件扫描的范围,例如
,因为您将实体放在package
at.naviclean.domain中

这将有助于您摆脱例外: 不是托管类型:类位于.naviclean.domain.Kassa

为了进一步调试,您可以尝试转储应用程序上下文(请参阅javadoc),以探索组件扫描检测到的类(如果某些类仍然无法识别),请检查它们的注释(@Service、@component等)

编辑:

您还需要将类添加到
persistence.xml

<persistence-unit>
    <class>at.naviclean.domain.Kassa</class>
     ...
</persistence-unit>

at.naviclean.domain.Kassa
...

我从奥利弗·吉尔克那里得到了一个非常有用的建议:

package at.naviclean.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@SuppressWarnings("serial")
@MappedSuperclass
public class ModelBase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Version
    @Column(name = "ts")
    private Date timestamp;

    public Long getId() {
        return id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

}
package at.naviclean.domain;

import javax.persistence.Column;
import javax.persistence.Entity;

@SuppressWarnings("serial")
@Entity
public class Kassa extends ModelBase {

    @Column(name = "name", unique = true)
    private String name;

    @Column(name = "geld")
    private int geld;

    public Kassa(String name, int geld) {
        this.name = name;
        this.geld = geld;
    }

    public Kassa() {
    }

    public String getName() {
        return name;
    }

    public int getGeld() {
        return geld;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGeld(int geld) {
        this.geld = geld;
    }

}
package at.naviclean.service;

import at.naviclean.domain.Kassa;

public interface MeinRemoteDienst {

    int getKassaCount(int plus);

    String getNameFromKassa(int id);

    Kassa findById(int id);
}
package at.naviclean.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import at.naviclean.domain.Kassa;

public interface KassaRepository extends BaseRepository<Kassa> {
    List<Kassa> findByGeld(int geld);

    Kassa findByName(String name);

    @Query("select k from Kassa k where k.geld = ?1")
    Kassa findByGeld1(int geld);
}
package at.naviclean.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import at.naviclean.domain.Kassa;
import at.naviclean.repositories.KassaRepository;
import at.naviclean.service.MeinRemoteDienst;

@Service
public class MeinRemoteDienstImpl implements MeinRemoteDienst {

    @Autowired(required = true)
    public KassaRepository kassaR;

    public int getKassaCount(int plus) {
        return 2;
    }


    public String getNameFromKassa(int id) {
        return kassaR.findById(id + 0l).getName();
    }

    @Override
    public Kassa findById(int id) {
        return = kassaR.findById(id + 0l);
    }

}
<?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:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <import resource="infrastructures.xml" />

    <jpa:repositories base-package="at.naviclean.repositories">
        <repository:exclude-filter type="regex"
            expression="at.naviclean.repositories.BaseRepository" />
    </jpa:repositories>

    <context:component-scan base-package="at.naviclean.service.impl" />

</beans>
<?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:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">



        <bean id="entityManagerFactory"
                class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="dataSource" />
                <property name="jpaVendorAdapter">
                        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                <property name="showSql" value="true" />
                                <property name="generateDdl" value="true" />
                                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
                        </bean>
                </property>
        </bean>

        <bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/kassatest" />
                <property name="username" value="root" />
                <property name="password" value="" />
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>


        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

</beans>
<?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:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



<import resource="../root-context.xml" />
    <bean id="idMeinRemoteDienst" class="at.naviclean.service.impl.MeinRemoteDienstImpl" />
    <bean name="/MeinRemoteDienstHessian"
        class="org.springframework.remoting.caucho.HessianServiceExporter"
        p:serviceInterface="at.naviclean.service.MeinRemoteDienst"
        p:service-ref="idMeinRemoteDienst" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="classpath:META-INF/spring/application-context.xml" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>/MeinRemoteDienstHessian</servlet-name>
        <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>

</web-app>
您得到的最后一个异常实际上表明您的JPA有问题 设置。“非托管bean”表示JPA提供者不知道的类型 属于如果您正在设置一个基于Spring的JPA应用程序,我推荐您 要在上配置“packagesToScan”属性,请执行以下操作: 已配置到包的LocalContainerEntityManagerFactory 它包含您的JPA实体。或者,您可以列出您的所有 persistence.xml中的实体类,但这通常更麻烦

您得到的前一个错误(NoClassDefFound)指示该类 在projects类路径上不可用。所以你可能 要检查您的模块间依赖关系。作为两个 相关类似乎也位于同一个模块中 只是Tomcat部署不完整的问题(WTP是一种 有时指恶毒的)。我绝对建议你为我的孩子做个测试 验证(正如您已经做的那样)。因为这似乎会把你带到一个 不同的例外,我想这真的是Eclipse的一些小故障


谢谢

参考奥利弗·吉尔克的提示:

当persistence.xml的操作成功时,您就创建了一个普通的java类而不是实体类

创建新实体类时,persistence.xml中的条目应该由Netbeans设置(在我的例子中)


但是正如Oliver Gierke所提到的,您可以稍后将条目添加到persistence.xml(如果您创建了一个普通的java类)。

在我的例子中,当使用IntelliJ时,我在项目中有多个模块。主模块依赖于另一个模块,该模块对Spring具有maven依赖性

主模块有
实体
s,第二个模块也有。但是当我运行主模块时,只有来自第二个模块的
实体
被识别为托管类


然后我又在主模块上添加了Spring依赖项,猜猜看是什么?它识别了所有的
实体。

在spring boot中,我使用Crudepository得到了相同的异常,因为我忘记设置泛型类型。我想把它写在这里,以防对某人有所帮助

错误定义:

public interface OctopusPropertiesRepository extends CrudRepository
public interface OctopusPropertiesRepository extends CrudRepository<OctopusProperties,Long>{
错误:

Caused by: java.lang.IllegalArgumentException: Not a managed type: class java.lang.Object
成功定义:

public interface OctopusPropertiesRepository extends CrudRepository
public interface OctopusPropertiesRepository extends CrudRepository<OctopusProperties,Long>{
公共接口OctopusPropertiesRepository扩展了Crudepository{

您需要检查软件包扫描

<bean id="entityManagerFactoryDB" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    <property name="dataSource" ref="dataSourceDB" />
    <property name="persistenceUnitName" value="persistenceUnitDB" />
    <property name="packagesToScan" value="at.naviclean.domain" />
                                            //here
 .....

当您间接扩展JpaRepository(KassaRepository扩展了扩展JpaRepository的BaseRepository)时,您必须使用
@NoRepositoryBean
注释BaseRepository:

@NoRepositoryBean
public interface BaseRepository<T extends ModelBase> extends JpaRepository<T, Long> {
    T findById(long id);
}
@NoRepositoryBean
公共接口BaseRepository扩展了JpaRepository{
T findById(长id);
}

根据@alfred_m的说法,对我来说,这个错误非常简单……tomcat有两个JAR,它们具有相同的类名和配置集

所发生的事情是…………我复制了我的现有项目,以便在现有项目的基础上创建一个新项目。但没有进行必要的更改,我开始处理其他项目。Henec 2项目具有相同的类和配置文件,导致冲突


删除了复制的项目并开始工作!!!!

如果有人遇到同样的问题,我通过在我的主类中添加
@EntityScan
解决了它。只需将模型包添加到basePackages属性。

遇到此问题并尝试了将实体PackageName添加到EntityScan的不同方法后,组件扫描等等,都不起作用

将包添加到存储库配置的EntityManagerFactory中的packageScan配置中。下面的代码给出了基于代码的配置,而不是上面回答的基于XML的配置

@Primary
@Bean(name = "entityManagerFactory")
public EntityManagerFactory entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource);
    emf.setJpaVendorAdapter(jpaVendorAdapter);
    emf.setPackagesToScan("org.package.entity");
    emf.setPersistenceUnitName("default"); 
    emf.afterPropertiesSet();
    return emf.getObject();
}

当您将不正确的实体对象传递给repository类中的Crudepository时,会出现相同的异常

public interface XYZRepository extends CrudRepository<IncorrectEntityClass, Long>
public interfa