Das Problem ist sehr seltsam. Meine IDE ist IDEA. Frühling Version ist 4.3.1.RELEASE.The Schlag meine Projektstruktur ist SpringMVC BeanCreationException: Erstellen Bean mit Name 'PersonService' in Datei PersonServiceImpl.class definiert?
Der Schlag ist web.xml (Simple)
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,
/WEB-INF/infrastructure.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/home/profile</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
Die apllicationContext.xml nur eine Zeile
<context:component-scan base-package="net.codespace.entity, net.codespace.DAO, net.codespace.service" />
Der Schlag ist SpringMVC-servlet.xml
<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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="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
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="net.codespace" />
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/home/" />
<property name="suffix" value=""/>
</bean>
</beans>
Die Pro sonDAO ist Schnittstelle. Der Code ist Blow
import net.codespace.entity.Person;
public interface PersonDAO {
public void save(Person p);
public void findAll();
}
PersonDAOImpl ist die Implementierung.
import net.codespace.entity.Person;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository("personDAO")
public class PersonDAOImpl implements PersonDAO{
@Autowired
private SessionFactory sessionFactory;
public void save(Person p){
}
public void findAll(){
}
}
Same, Die PersonService Schnittstelle,
package net.codespace.service;
/**
* Created by mark on 2016/7/26.
*/
import net.codespace.entity.Person;
public interface PersonService {
public void savePerson(Person p);
public void getAllPerson(Person p);
}
PersonServiceImpl ist Schlag
import net.codespace.entity.Person;
import net.codespace.DAO.PersonDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service("personService")
@Transactional
public class PersonServiceImpl implements PersonService{
@Autowired
private PersonDAO personDAO;
public void savePerson(Person p){
}
public void getAllPerson(Person p){
System.out.println("punk your pieese");
}
}
Die pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.markliang</groupId>
<artifactId>lsc-toy</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<jackson.version>2.6.3</jackson.version>
<hibernate.version>4.3.5.Final</hibernate.version>
<spring.version>4.3.1.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>5.5.23</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.31</version>
</dependency>
</dependencies>
</project>
Als ich dieses Projekt bereitstellen, bekam ich diese Fehler (Wichtig anzeigen)
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService' defined in file
[C:\Users\mark\IdeaProjects\SMS01\out\artifacts\SMS01_war_exploded\WEB-INF\classes\net\codespace\service\PersonServiceImpl.class]: Post-processing failed of bean type [class net.codespace.service.PersonServiceImpl] failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [net.codespace.service.PersonServiceImpl] for persistence metadata: could not find class that it depends on
Caused by: java.lang.IllegalStateException: Failed to introspect bean class [net.codespace.service.PersonServiceImpl] for
persistence metadata: could not find class that it depends on
/* some info */
Caused by: java.lang.NoClassDefFoundError: Lnet/codespace/DAO/PersonDAO;
/* some info */
Caused by: java.lang.ClassNotFoundException: net.codespace.DAO.PersonDAO
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1891)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1734)
/*some info */
Könnte mir jemand helfen? Wenn Sie mehr Detailinformationen benötigen, kann ich Ihnen eine Mail senden. Danke
Bitte zeigen Sie Ihre PersonService-Schnittstelle. –
Ja, habe es zu der Frage hinzufügen – markliang
Kannst du den Code von 'PersonDAO' zeigen? Haben Sie Ihren Code kürzlich kompiliert? –