简体   繁体   English

Spring MVC LightAdmin配置

[英]Spring MVC LightAdmin configuration

I'm trying to setup LightAdmin page for my web application, I'm following https://github.com/la-team/light-admin . 我正在尝试为我的Web应用程序设置LightAdmin页面,正在关注https://github.com/la-team/light-admin After following this step a see this error: 执行完此步骤后,看到此错误:

 14:36:55.705 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@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}

Here is my web.xml file: 这是我的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: 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>

and root_context.xml: 和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 "> 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>

Could you help me? 你可以帮帮我吗? I'm trying to have admin page to create/update/delete/show Users and Teams. 我正在尝试使用管理页面来创建/更新/删除/显示用户和团队。 Or is there a better way how to do it? 还是有更好的方法呢?

The message is referring to an absence of persistence.xml file. 该消息是指缺少persistence.xml文件。 This file is usually holding references of the entities you defined for Hibernate/JPA. 该文件通常包含您为Hibernate / JPA定义的实体的引用。

Based on the files you submitted I was not completely able to reproduce your issue, do you have a way to share your project on GitHub ? 根据您提交的文件,我无法完全重现您的问题,您是否有办法在GitHub上共享您的项目? Can you provide a bit extra insights about how you're deploying it ? 您能否提供一些有关如何部署它的额外见解?

I took a quick look at your project. 我快速浏览了您的项目。 I don't see where you are using jpa, it seems you are using jdbctemplate for data access. 我看不到您在哪里使用jpa,似乎您正在使用jdbctemplate进行数据访问。

Why don't you remove these lines from your config and see if that gets you farther. 您为什么不从配置中删除这些行,看看是否能使您走得更远。

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

If you configure jpa related beans you are telling Spring-Boot not to auto-configure, and then you are responsible for replacing the "magic" that the framework does for you. 如果您配置了与jpa相关的bean,那么您将告诉Spring-Boot不要自动配置,然后负责替换框架为您完成的“魔术”。

Spring boot should provide reasonable default configurations. Spring Boot应该提供合理的默认配置。 You can add specific configuration later when-and-if you start using JPA(entities, repositories, etc) to access your data. 如果以后开始使用JPA(实体,存储库等)来访问数据,则可以添加特定的配置。

In your HomeController could you try this: 您可以在HomeController中尝试以下操作:

@Autowired
private UserJDBCTemplate userJDBCTemplate;

@Autowired
private TeamJDBCTemplate teamJDBCTemplate;

instead of this: 代替这个:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM