当前位置: 首页 > 面试题库 >

在Spring中更新属性文件中的数据库设置

游皓
2023-03-14
问题内容

我刚接触Spring,我试图创建一个Database Manager页面,该页面显示页面加载时的数据库详细信息,并在用户按下Submit时更新数据库设置。

我遵循了本教程,并在属性文件中设置了数据库设置。

我设法以编程方式更新了属性文件中的数据库设置。当我使用以下代码检索数据库设置时

DriverManagerDataSource databaseSource = (DriverManagerDataSource)context.getBean("dataSource");
databaseSource.getUsername();

我设法获得了旧的价值而无法获得新的价值

这是applicationContext.xml文件中的映射

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

    <property name="location">
        <value>classpath:/bundle/database.properties</value>
    </property>
</bean>

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">

    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

我检查了属性文件,发现它已使用最新输入进行更新。

我想念什么?

提前致谢

PS我在Spring 3中使用JSF1.2

更新资料

只是使我的要求简单。我正在创建一个setparate
dbsettings页面,以便当用户希望连接到其他数据库时,他/她只需在dbsettings页面中输入详细信息并连接

更新资料

我使用此代码来检索应用程序上下文

private ApplicationContext context;

....

ServletContext servletContext = FacesUtil.getServletContext();
    this.context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);

如果将其更改为AbstractApplicationContext,则在上面的代码中我需要什么更改?

更新

this.context = (AbstractApplicationContext)WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    String valueForTheProperty = "";


    context.refresh();

当我在上面添加行时

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is java.lang.NullPointerException
org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:599)
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377)
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:263)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy1.getDatabasePasswordFromSettings(Unknown Source)
com.smartcall.delegate.DbSettingsDelegate.getDatabasePassswordFromSettings(DbSettingsDelegate.java:38)
com.smartcall.bean.DbSettingsBean.loadDatabaseSettings(DbSettingsBean.java:49)
com.smartcall.bean.DbSettingsBean.<init>(DbSettingsBean.java:41)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
java.lang.Class.newInstance0(Class.java:355)
java.lang.Class.newInstance(Class.java:308)
com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:185)
com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:368)
com.sun.faces.mgbean.BeanManager.create(BeanManager.java:230)
com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)
org.apache.el.parser.AstValue.getValue(AstValue.java:112)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:246)
com.sun.facelets.tag.jsf.ComponentHandler.createComponent(ComponentHandler.java:224)
com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:139)
com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
com.sun.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:109)
com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:524)
com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)
org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)

root cause

java.lang.NullPointerException
org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.nextTimestamp(RegionFactoryCacheProviderBridge.java:85)
org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:526)
org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:535)
org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:493)
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377)
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:263)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy1.getDatabasePasswordFromSettings(Unknown Source)
com.smartcall.delegate.DbSettingsDelegate.getDatabasePassswordFromSettings(DbSettingsDelegate.java:38)
com.smartcall.bean.DbSettingsBean.loadDatabaseSettings(DbSettingsBean.java:49)
com.smartcall.bean.DbSettingsBean.<init>(DbSettingsBean.java:41)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
java.lang.Class.newInstance0(Class.java:355)
java.lang.Class.newInstance(Class.java:308)
com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:185)
com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:368)
com.sun.faces.mgbean.BeanManager.create(BeanManager.java:230)
com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)
org.apache.el.parser.AstValue.getValue(AstValue.java:112)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:246)
com.sun.facelets.tag.jsf.ComponentHandler.createComponent(ComponentHandler.java:224)
com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:139)
com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
com.sun.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:109)
com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:524)
com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)
org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)

当我注释掉该行时

context.refresh()

应用程序运行正常。请帮助

更新

DBSettingBean

public DbSettingsBean()
{
    dbSettingsDelegate = new DbSettingsDelegate();

    loadDatabaseSettings();
    submitButton.setRendered(false);
    testButton.setRendered(true);
}

public void loadDatabaseSettings()
{
    this.setUserName(dbSettingsDelegate.getDatabaseUserNameFromSettings());
    this.setPassword(dbSettingsDelegate.getDatabasePassswordFromSettings());
    this.setServerName(dbSettingsDelegate.getDatabaseServerNameFromSettings());
    this.setDataSourceName(dbSettingsDelegate.getDatabaseNameFromSettings());
}

public HtmlOutputText getText()
{
    return text;
}



public void setText(HtmlOutputText text)
{
    this.text = text;
}



public HtmlAjaxCommandButton getSubmitButton()
{
    return submitButton;
}



public void setSubmitButton(HtmlAjaxCommandButton submitButton)
{
    this.submitButton = submitButton;
}



public HtmlCommandButton getTestButton()
{
    return testButton;
}



public void setTestButton(HtmlCommandButton testButton)
{
    this.testButton = testButton;
}



public HtmlOutputText getStatusMessageComponent()
{
    return statusMessageComponent;
}

public void setStatusMessageComponent(HtmlOutputText statusMessageComponent)
{
    this.statusMessageComponent = statusMessageComponent;
}

public UIInput getPassworder()
{
    return passworder;
}

public void setPassworder(UIInput passworder)
{
    this.passworder = passworder;
}

public String getServerName()
{
    return serverName;
}

public void setServerName(String serverName)
{
    this.serverName = serverName;
}

public String getDataSourceName()
{
    return dataSourceName;
}

public void setDataSourceName(String dataSourceName)
{
    this.dataSourceName = dataSourceName;
}

public String getUserName()
{
    return userName;
}

public void setUserName(String userName)
{
    this.userName = userName;
}

public String getPassword()
{
    return password;
}

public void setPassword(String password)
{
    this.password = password;
}

public String testWhetherTheConnectionExists()
{       
    return dbSettingsDelegate.checkWhetherDatabaseConnectionExists(getUserName(), getPassword(), getDataSourceName(),getServerName());
}

和..

DbSettingsDelegate

public DbSettingsDelegate()
{
    try 
    {
        System.out.println("Dbsettings delegate: "+FacesContext.getCurrentInstance());
        dbSettingsService = (DbSettingsService) ServiceLocator
                        .getInstance().getService(
                        ServiceLocator.Services.DBSETTINGS);
    } 
    catch (Exception e) 
    {
        logger.debug("error in AddressBookDelegate constructor", e);
    }
}

public String getDatabaseUserNameFromSettings()
{
    return dbSettingsService.getDatabaseUserNameFromSettings();
}

public String getDatabasePassswordFromSettings()
{
    return dbSettingsService.getDatabasePasswordFromSettings();
}

public String getDatabaseServerNameFromSettings()
{
    return dbSettingsService.getDatabaseServerNameFromSettings();
}

public String getDatabaseNameFromSettings()
{
    return dbSettingsService.getDatabaseNameFromSettings();
}

public String checkWhetherDatabaseConnectionExists(String theUserName,String thePassword,String theDatabaseName,String theServerName)
{
    return dbSettingsService.checkWhetherTheDatabaseConnectionExists(theUserName, thePassword, theDatabaseName, theServerName);
}

这是检索数据库详细信息以显示给用户的代码

ServletContext servletContext = FacesUtil.getServletContext();
    this.context = (AbstractApplicationContext)WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    String valueForTheProperty = "";
    DriverManagerDataSource databaseSource =  null;

    context.refresh();
    databaseSource = (DriverManagerDataSource)context.getBean("dataSource");



    if(theProperty.equalsIgnoreCase("username"))
    {
        valueForTheProperty = databaseSource.getUsername();
    }       
    else if(theProperty.equalsIgnoreCase("password"))
    {
        valueForTheProperty = databaseSource.getPassword();
    }
    else if(theProperty.equalsIgnoreCase("server"))
    {           
        valueForTheProperty = this.splitUrlAndGetValueForKey(databaseSource.getUrl(), "server");
        System.out.println("Server:  "+valueForTheProperty);
    }
    else
    {
        valueForTheProperty = this.splitUrlAndGetValueForKey(databaseSource.getUrl(), "databasename");
    }

更新 当我调试代码时,我在控制台中发现了以下几行。何时context.refresh()

Dec 28, 2010 3:22:44 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
Dec 28, 2010 3:22:44 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
Dec 28, 2010 3:22:44 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
Dec 28, 2010 3:22:44 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete

因此,我可以假设进行了一些更新。无法确定我为什么继续获得旧价值

UPDATE 完整的applicationCOntext.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" scope="prototype">

    <property name="location">
        <value>classpath:/bundle/database.properties</value>
    </property>
</bean>

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">

    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>


<!-- Hibernate SessionFactory Definition -->
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">


    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.MySQLDialect
            </prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">
                true
            </prop>
            <prop key="hibernate.cache.provider_class">
                org.hibernate.cache.HashtableCacheProvider
            </prop>
            <prop key="hibernate.connection.useUnicode">true</prop>
            <prop key="hibernate.connection.characterEncoding">UTF-8</prop>
        </props>
    </property>

    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
</bean>

<!-- Spring Data Access Exception Translator Definition -->
<bean id="jdbcExceptionTranslator"
    class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
</bean>

<!-- Hibernate Template Definition -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
    <property name="jdbcExceptionTranslator">
        <ref bean="jdbcExceptionTranslator" />
    </property>
</bean>

<!--
    ========================= Start of SERVICE DEFINITIONS
    =========================
-->

<!-- Hibernate Transaction Manager Definition -->
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref local="sessionFactory" />
    </property>
</bean>

<!-- AddressBook Service Definition -->
<bean id="loginServiceTarget" class="com.smartcall.service.impl.LoginServiceImpl">
    <property name="loginDAO">
        <ref local="loginDAO" />
    </property>
</bean>

<!-- Login DAO Definition: Hibernate implementation -->
<bean id="loginDAO"
    class="com.smartcall.dao.hibernate.HibernateLoginDAO">
    <property name="hibernateTemplate">
        <ref bean="hibernateTemplate" />
    </property>
</bean>

<!-- Transactional proxy for the AddressBook Service -->
<bean id="loginService"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
        <ref local="transactionManager" />
    </property>
    <property name="target">
        <ref local="loginServiceTarget" />
    </property>
    <property name="transactionAttributes">
        <props>
            <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
            <prop key="save*">PROPAGATION_REQUIRED</prop>
            <prop key="update*">PROPAGATION_REQUIRED</prop>
            <prop key="delete*">PROPAGATION_REQUIRED</prop>
        </props>
    </property>
</bean>

context.refresh()刷新了我认为的整个applicationContext
bean。好的,现在我删除了它们之间的代理和服务,应用程序现在直接调用

我现在不使用DBSettingsDelegate

更新

更新属性文件代码

Properties properties = new Properties();
    String a = Thread.currentThread()
                .getContextClassLoader()
                .getResource("/com/smartcall/bundle/database.properties").getFile();

    a = a.replaceAll("%20", " ");
    String url = "";

        url = "jdbc:mysql://"+theServerName+":3306/"+theDatabaseName+"?characterEncoding=UTF-8";
        File file = new File(a);
        //file.setWritable(true);

        System.out.println(url);
        System.out.println(file.getAbsolutePath());

        FileInputStream stream = new FileInputStream(file);
        properties.load(stream);

        properties.put("jdbc.username", theUserName);
        properties.put("jdbc.password", thePassword);
        properties.put("jdbc.url", url);

        properties.store(new FileOutputStream(file),null);

问题答案:

您需要刷新
Application上下文并DriverManagerDataSource再次获取Bean ,以反映写入属性文件的更改。

context.refresh();
DriverManagerDataSource databaseSource = (DriverManagerDataSource)context.getBean("dataSource");
databaseSource.getUsername();

获取资源文件对象的提示:

    URI a = getClass().getResource("/com/smartcall/bundle/database.properties").toURI();
    File file = new File(a);

您无需解码路径,即用“”替换%20。推荐人



 类似资料:
  • 问题内容: 我对使用Spring应用程序的属性文件中的值进行写入/更新时有一些要求。 我已经用谷歌搜索过,但是我没有找到使用Spring的直接方法。 是否有人知道该怎么做或是否有最佳方法。 提前致谢。 问题答案: 您可以这样实现: 资源 编辑:使用来自org.springframework.Util的defaultPropertiesPersiter更新

  • 我有一个discord机器人,通过连接github repo在heroku中托管,因此我有一个命令,该命令使用作者ID更新sql数据库,当我在PC中进行测试时,它正在更新,但在github中添加文件和新代码后,sql文件没有得到更新这些是代码

  • 问题内容: 在hibernateHBM文件中,设置以下属性的目的是什么? 他们的目的是什么?它们对性能有何影响?我们什么时候应该使用它们? 问题答案: 从文档中: 更新,插入(可选-默认为true):指定映射的列应包含在SQL UPDATE和/或INSERT语句中。将两者都设置为false将允许使用纯的“派生”属性,其值是通过映射到同一列的其他某个属性或触发器或其他应用程序初始化的。

  • 问题内容: 我从log4j开始已经有一段时间了。非常酷的日志记录框架。我完成了其他类型的日志记录,例如控制台和文件日志记录。因此,尝试使用mysql的数据库适配器进行数据库日志记录。因此,我创建了名为log4j.properties的以下属性文件,其内容为- 并按以下方式在测试类中使用了它- 但我收到以下错误- 有什么帮助吗…? 问题答案: 如果您使用的是mysql。创建一个文件log4j.pro

  • 问题内容: 我是Spring框架的新手。在我的Spring应用程序中,有一些细节,如下所述,这些细节需要在属性文件中维护。 在我的控制器中,有一个如下操作。 根据请求参数 提供者, 我需要获取相关的交易类型ID。例如,如果提供者为 TXT_CCO ,则事务类型id应为 70001 。 有人可以帮我实现这个目标吗 问题答案: 我会说你有2个选择 使用加载属性 使用和抽象。 使用 要简单地加载属性文件

  • 出于监管和安全的原因,我不得不将Spring boot应用程序的逻辑拆分为两个工具:一个用于管理有限数量的表,另一个用于“真正的”用户应用程序。因此,我在服务器版本5.7上有两个MySQL数据库实例。虽然用户工具只访问一个包含几十个表的数据库,但管理工具需要访问两个数据库中的实体。 这些工具都是基于JavaFX和Spring Boot的。由于这种体系结构设置,我有三个maven包:一个用于管理工具