小编joh*_*and的帖子

使用JNDI数据源进行Spring Boot

我有一个新的Spring Boot Web应用程序,我想连接到JNDI数据源(在Tomcat的context.xml中定义的MySQL数据库).

但是,当我尝试这个时,我总是得到以下异常;

org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database url for database type NONE. If you want an embedded database please put a supported on on the classpath.
Run Code Online (Sandbox Code Playgroud)

尽管我的pom.xml包含MySQL连接器

<?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>org.test</groupId>
<artifactId>twojndi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>Two JNDI Data Sources</name>
<description>Two JNDI Data Sources Example</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.8.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-jdbc</artifactId>
                <groupId>org.apache.tomcat</groupId> …
Run Code Online (Sandbox Code Playgroud)

spring jndi spring-boot

8
推荐指数
1
解决办法
2万
查看次数

如何重新运行Spring Batch作业?

我已经定义了一个Spring Batch作业,它运行一次就好了.但是,由于JOB_INSTANCE_ID的主键中存在重复条目,因此无法再次运行;

SEVERE: Job Terminated in error: PreparedStatementCallback; SQL [INSERT into    BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; Duplicate entry '0' for key 'PRIMARY'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'PRIMARY'
Run Code Online (Sandbox Code Playgroud)

我已经读过,可以通过在作业上设置命令行参数来解决这个问题,例如

java -cp ${CLASSPATH} org.springframework.batch.core.launch.support.CommandLineJobRunner myJob.xml myJob date=20121025154016 -next
Run Code Online (Sandbox Code Playgroud)

无论我是否包含-next参数,它都不会运行该作业.

我的Spring Batch配置如下所示(batch/launchContext.xml);

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

    <!-- Launch context: how to launch all of the jobs …
Run Code Online (Sandbox Code Playgroud)

spring spring-batch

1
推荐指数
1
解决办法
8013
查看次数

标签 统计

spring ×2

jndi ×1

spring-batch ×1

spring-boot ×1