2015-10-16 179 views
0

我想爲我的web應用程序安裝LightAdmin頁面,我正在關注https://github.com/la-team/light-admin。下面這個步驟後,看到此錯誤:Spring MVC LightAdmin配置

14:36:55.705 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.s[email protected]77bc4d5: defining beans [dataSource,userJDBCTemplate,teamJDBCTemplate,entityManagerFactory,transactionManager]; root of factory hierarchy 
14:36:55.708 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml} 
.... 
Caused by: java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml} 

這裏是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 

<!-- 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> 

<context-param> 
    <param-name>light:administration:base-url</param-name> 
    <param-value>/admin</param-value> 
</context-param> 

<context-param> 
    <param-name>light:administration:security</param-name> 
    <param-value>true</param-value> 
</context-param> 

<context-param> 
    <param-name>light:administration:base-package</param-name> 
    <param-value>com.project.config</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> 

<!-- Processes application requests --> 
<servlet> 
    <servlet-name>appServlet</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>appServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

的pom.xml:

<?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/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.wirecardproject</groupId> 
<artifactId>project</artifactId> 
<name>Wirecard project</name> 
<packaging>war</packaging> 
<version>1.0.0-BUILD-SNAPSHOT</version> 
<properties> 
    <java-version>1.6</java-version> 
    <org.springframework-version>4.2.1.RELEASE</org.springframework-version> 
    <org.aspectj-version>1.6.10</org.aspectj-version> 
    <org.slf4j-version>1.6.6</org.slf4j-version> 
</properties> 
<dependencies> 
    <!-- Spring --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${org.springframework-version}</version> 
     <exclusions> 
      <!-- Exclude Commons Logging in favor of SLF4j --> 
      <exclusion> 
       <groupId>commons-logging</groupId> 
       <artifactId>commons-logging</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 

    <!-- AspectJ --> 
    <dependency> 
     <groupId>org.aspectj</groupId> 
     <artifactId>aspectjrt</artifactId> 
     <version>${org.aspectj-version}</version> 
    </dependency> 

    <!-- LightAdmin --> 
    <dependency> 
     <groupId>org.lightadmin</groupId> 
     <artifactId>lightadmin</artifactId> 
     <version>1.2.0.BUILD-SNAPSHOT</version> 
    </dependency> 

    <!-- @Inject --> 
    <dependency> 
     <groupId>javax.inject</groupId> 
     <artifactId>javax.inject</artifactId> 
     <version>1</version> 
    </dependency> 

    <!-- Servlet --> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet.jsp</groupId> 
     <artifactId>jsp-api</artifactId> 
     <version>2.1</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version> 
    </dependency> 

    <!-- Test --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.7</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
     <version>1.2.5.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <version>1.2.5.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
     <version>2.3.3</version> 
    </dependency> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.35</version> 
    </dependency> 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-eclipse-plugin</artifactId> 
      <version>2.9</version> 
      <configuration> 
       <additionalProjectnatures> 
        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> 
       </additionalProjectnatures> 
       <additionalBuildcommands> 
        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> 
       </additionalBuildcommands> 
       <downloadSources>true</downloadSources> 
       <downloadJavadocs>true</downloadJavadocs> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.5.1</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
       <compilerArgument>-Xlint:all</compilerArgument> 
       <showWarnings>true</showWarnings> 
       <showDeprecation>true</showDeprecation> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.2.1</version> 
      <configuration> 
       <mainClass>org.test.int1.Main</mainClass> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

和root_context.xml:

<?xml version="1.0" encoding="UTF-8"?> 

http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd「>

<!-- Definition for userJDBCTemplate bean --> 
<bean id="userJDBCTemplate" class="users.UserJDBCTemplate"> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 

<!-- Definition for scriptJDBCTemplate bean --> 
<bean id="teamJDBCTemplate" class="teams.TeamJDBCTemplate"> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 
<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> 
</bean> 

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

你能幫我嗎?我試圖讓管理頁面創建/更新/刪除/顯示用戶和團隊。或者有更好的方法來做到這一點?

回答

0

該消息指的是缺少persistence.xml文件。該文件通常包含您爲Hibernate/JPA定義的實體的引用。

根據您提交的文件,我無法完全重現您的問題,您是否有辦法在GitHub上共享您的項目?你能否提供一些關於你如何部署它的更多見解?

+0

我剛剛開始,所以我在本地部署它用我的春天工具套件IDE和樞紐tc服務器開發版。這是我在GitHub上的項目,如果你知道一個問題,那對我來說會很有幫助。 https://github.com/LenkaDzurjakova/project.git – Lenusska1414

0

我快速查看了您的項目。我沒有看到你使用jpa的地方,看起來你正在使用jdbctemplate進行數據訪問。

爲什麼不從配置中刪除這些行,看看是否讓你更遠。

<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> 
</bean> 

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

如果配置JPA相關豆你告訴彈簧開機不自動配置,然後你負責更換的「魔術」,該框架爲您做。

Spring引導應該提供合理的默認配置。稍後您可以添加特定配置,並且如果您開始使用JPA(實體,存儲庫等)來訪問您的數據。

在你的HomeController,你可以試試這個:

@Autowired 
private UserJDBCTemplate userJDBCTemplate; 

@Autowired 
private TeamJDBCTemplate teamJDBCTemplate; 

,而不是這樣的:

ApplicationContext context = new ClassPathXmlApplicationContext("root-context.xml"); 

    UserJDBCTemplate ubd =(UserJDBCTemplate)context.getBean("userJDBCTemplate"); 
    TeamJDBCTemplate tbd =(TeamJDBCTemplate)context.getBean("teamJDBCTemplate"); 
+0

我試着你的建議,但現在我得到 java.lang.IllegalStateException:沒有找到WebApplicationContext:沒有ContextLoaderListener或DispatcherServlet註冊? \t org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:252) \t org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) \t org.springframework.web.filter。 OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) – Lenusska1414