springboot出现数据源错误

xt0899hw  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(321)

我在运行spring boot项目时遇到了一个问题:
我使用vaadin作为ui,maven作为dependecies。这个数据库是mysql数据库,我已经按照(https://spring.io/guides/gs/accessing-data-mysql/)非常接近。
说明:
org.springframework.boot.autoconfigure.orm.jpa.hibernatejbaaautoconfiguration中构造函数的参数0需要找不到类型为“javax.sql.datasource”的bean。-未加载bean方法“datasource”,因为@conditionalonproperty(spring.datasource.jndi name)未找到属性“jndi name”-未加载bean方法“datasource”,因为@conditionalonbean(类型:org.springframework.boot.jta.xadatasourcewrapper;searchstrategy:all)未找到任何bean
行动:
考虑重新访问上述条件或在配置中定义“javax.sql.datasource”类型的bean。
with--debug:完整的自动配置报告(对于本文来说太长)
https://pastebin.com/desakpli
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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ethereum</groupId>
    <artifactId>TradeSafe</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>TradeSafe</name>
    <description>TradeSafe WebService</description>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.web3j</groupId>
            <artifactId>core</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.web3j</groupId>
            <artifactId>web3j-spring-boot-starter</artifactId>
            <version>1.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>8.0.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
        <repository>
            <id>org.jboss.repository.releases</id>
            <name>JBoss Maven Release Repository</name>
            <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
        </repository>
    </repositories>

</project>

贸易布局.java

package ethereum.tradesafe;

import java.util.List;

import javax.annotation.PostConstruct;

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

import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.ui.GridLayout;

@SpringComponent
public class TradeLayout extends GridLayout{
    @Autowired
    private TradeRepo repo;

    @PostConstruct
    void init() {
        update();
    }

    private void setTrades(List<Trade> trades) {
        removeAllComponents();

        trades.forEach(trade-> addComponent(new TradeItemLayout(trade)));

    }

    public Object add(Trade trade) {
        repo.save(trade);
        update();
        return null;
    }

    private void update() {
        setTrades((List<Trade>) repo.findAll());

    }

}

贸易回购.java

package ethereum.tradesafe;

import org.springframework.data.repository.CrudRepository;

public interface TradeRepo extends CrudRepository<Trade, Long>{

}

应用程序属性

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://nottheproblem/db_tradesafe
spring.datasource.username=nottheproblem
spring.datasource.password=nottheproblem
wlwcrazw

wlwcrazw1#

尝试在traderepo上方添加@repository注解,并将其重命名为traderepository

相关问题