在这种情况下,会出现“创建名为’Liquibase’的Bean时出错”的错误。

huangapple go评论68阅读模式
英文:

Error Creating Bean with Name 'Liquibase'

问题

以下是你提供的内容的翻译:

我正在创建一个使用Spring Boot和VueJS的Web应用程序,并且正在按照一个教程进行操作。在初始设置阶段,我遇到了一个错误,经过在其他Stack Overflow论坛上搜索后仍然无法解决。错误信息如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.DatabaseException: java.sql.SQLException: Access denied for user 'username'@'localhost' (using password: YES)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	

以下是我的changelog.xml文件内容:

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

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <changeSet id="1" author="sha">
        <sql>
            CREATE TABLE user {
                id BIGINT NOT NULL AUTO_INCREMENT,
                name VARCHAR(255) NOT NULL,
                username VARCHAR(255) NOT NULL,
                password VARCHAR(255) NOT NULL,
                role VARCHAR(255) NOT NULL,
                CONSTRAINT PK_id PRIMARY KEY (id)
            };
        </sql>
        <rollback>
            DROP TABLE user
        </rollback>
    </changeSet>
</databaseChangeLog>

这是我的master.xml文件内容:

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

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <include file="db/changelog/db.changelog-1.0.xml" />
</databaseChangeLog>

在changelog中,我需要做哪些更改才能解决这个问题?

英文:

I'm creating a Spring Boot/VueJS Web app and am following a tutorial where the initial setup has resulted in an error that I can't figure out after searching other Stack Overflow forums. The error is:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;liquibase&#39; defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.DatabaseException: java.sql.SQLException: Access denied for user &#39;username  &#39;@&#39;localhost&#39; (using password: YES)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:311) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at com.sha.serverusermanagement.ServerUserManagementApplication.main(ServerUserManagementApplication.java:10) ~[classes/:na]

Below is my changelog.xml file:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;databaseChangeLog
        xmlns=&quot;http://www.liquibase.org/xml/ns/dbchangelog&quot;
        xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
        xmlns:ext=&quot;http://www.liquibase.org/xml/ns/dbchangelog-ext&quot;
        xsi:schemaLocation=&quot;http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd&quot;&gt;

    &lt;changeSet id=&quot;1&quot; author=&quot;sha&quot;&gt;
        &lt;sql&gt;
            CREATE TABLE user {
                id BIGINT NOT NULL AUTO_INCREMENT,
                name VARCHAR(255) NOT NULL,
                username VARCHAR(255) NOT NULL,
                password VARCHAR(255) NOT NULL,
                role VARCHAR(255) NOT NULL,
                CONSTRAINT PK_id PRIMARY KEY (id)
            };
        &lt;/sql&gt;
        &lt;rollback&gt;
            DROP TABLE user
        &lt;/rollback&gt;
    &lt;/changeSet&gt;
&lt;/databaseChangeLog&gt;

Here is also my master.xml file:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;databaseChangeLog
        xmlns=&quot;http://www.liquibase.org/xml/ns/dbchangelog&quot;
        xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
        xmlns:ext=&quot;http://www.liquibase.org/xml/ns/dbchangelog-ext&quot;
        xsi:schemaLocation=&quot;http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd&quot;&gt;
    &lt;include file=&quot;db/changelog/db.changelog-1.0.xml&quot; /&gt;
&lt;/databaseChangeLog&gt;

What must I change in the changelog in order to fix this issue?

答案1

得分: 2

如果你查看异常消息字符串的末尾,你会看到这个:

Access denied for user 'username  ' @ 'localhost' (using password: YES)

仔细看。你在尝试用登录用户名登录数据库时末尾有一个空格。我敢打赌这不是你想要的,很可能正是你的代码没有按预期执行的原因。

从你的代码中我看不出数据库登录用户名是从哪里来的,但如果你能找到并修复它以移除这个空格,我希望你的代码会正常运行。

英文:

If you look at the end of the Exception's message String, you'll see this:

Access denied for user &#39;username  &#39;@&#39;localhost&#39; (using password: YES)

Look closely. You've got a space at the end of the login username that you're trying to log into the database with. I bet this isn't what you intended, and it could very well be exactly why your code isn't doing what you expect.

I can't see from your code where the database login username comes from, but if you can find and fix that to remove the space, I'm hoping that your code will then run correctly.

答案2

得分: 0

我确定这些错误的原因是因为没有将访问权限授予我的MySQL用户以访问新创建的数据库。现在一切都正常了。感谢您的输入!

英文:

I determined that the reason for these errors was because of not granting access to my MySQL user to the newly created database. It's all good now. Thanks for your inputs!

huangapple
  • 本文由 发表于 2020年9月15日 03:49:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63890975.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定