当前位置: 首页 > 知识库问答 >
问题:

重启/重新加载Spring Data MongoDB

洪凯定
2023-03-14

在我的项目中,我使用属性占位符读取属性文件,其中包含数据库连接的配置。在我的初始设置和重新配置过程中,我希望能够更改数据库主机的详细信息。

我尝试使用在当前应用程序上下文中调用的刷新()方法,但不知何故没有重新加载Spring Data Bean,并且我得到了Spring Data发出的IllegalStateException:

HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalStateException: open
Exception report: Message: Request processing failed; nested exception is java.lang.IllegalStateException: open description: The server encountered an internal error that prevented it from fulfilling this request. exception: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: open
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
root cause: java.lang.IllegalStateException: open
    org.bson.util.Assertions.isTrue(Assertions.java:36)
    com.mongodb.DBTCPConnector.getPrimaryPort(DBTCPConnector.java:408)
    com.mongodb.DBCollectionImpl.update(DBCollectionImpl.java:263)
    com.mongodb.DBCollection.update(DBCollection.java:191)
    com.mongodb.DBCollection.save(DBCollection.java:975)
    com.mongodb.DBCollection.save(DBCollection.java:934)
    org.springframework.data.mongodb.core.MongoTemplate$10.doInCollection(MongoTemplate.java:950)
    org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:410)
    org.springframework.data.mongodb.core.MongoTemplate.saveDBObject(MongoTemplate.java:945)
    org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:885)
    org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:833)
    org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:73)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:483)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:442)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:427)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:381)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodInterceptor.invoke(RepositoryFactorySupport.java:512)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    com.sun.proxy.$Proxy2987.save(Unknown Source)
    de.steilerdev.myVerein.server.controller.InitController.initSuperAdmin(InitController.java:158)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:483)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)

不幸的是,我对bean及其生命周期不是很有信心,所以我需要帮助重新加载适当的bean。我也可以重新启动Spring应用程序本身,尽管这是一个昂贵的操作。因为它很少需要,所以我可以接受它的成本。

我不确定您需要哪部分代码,但这里有一个指向Github存储库的链接。(很抱歉文档太差,仍处于项目开始阶段)

谢谢

编辑:该过程中涉及的一些类:

施泰勒德夫。米韦林。服务器控制器。InitController(接收相关请求,将设置存储到my settings Repository)

@Controller
@RequestMapping("/init")
public class InitController
{
    @Autowired
    private SettingsRepository settingsRepository;

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private DivisionRepository divisionRepository;

    @Autowired
    private ReloadableResourceBundleMessageSource messageSource;

    private static Logger logger = LoggerFactory.getLogger(InitController.class);

    @RequestMapping(value = "settings")
    public ResponseEntity<String> initSettings(@RequestParam String clubName,
                                               @RequestParam String databaseHost,
                                               @RequestParam String databasePort,
                                               @RequestParam String databaseUser,
                                               @RequestParam String databasePassword,
                                               @RequestParam String databaseCollection,
                                               @RequestParam String rememberMeTokenKey,
                                               Locale locale)
    {
        logger.debug("Starting initial configuration");
        if(!settingsRepository.isInitSetup())
        {
            logger.warn("An initial setup API was used, even though the system is already configured.");
            return new ResponseEntity<>(messageSource.getMessage("init.message.settings.notAllowed", null, "You are not allowed to perform this action at the moment", locale), HttpStatus.BAD_REQUEST);
        } else if(clubName.isEmpty() || rememberMeTokenKey.isEmpty())
        {
            logger.warn("The club name or remember me key is not present");
            return new ResponseEntity<>(messageSource.getMessage("init.message.settings.noKeyOrName", null, "The club name and remember me key is required", locale), HttpStatus.BAD_REQUEST);
        } else
        {
            int databasePortInt = 27017;
            if(databaseHost.isEmpty())
            {
                logger.warn("The database host is empty, using default value.");
                databaseHost = "localhost";
            }
            if(databasePort.isEmpty())
            {
                logger.warn("The database port is empty, using default value.");
                databasePort = "27017";
            } else
            {
                try
                {
                    databasePortInt = Integer.parseInt(databasePort);
                } catch (NumberFormatException e)
                {
                    logger.warn("The database port seems not to be a number " + databasePort);
                    return new ResponseEntity<>(messageSource.getMessage("init.message.settings.dbPortNoNumber", null, "The database port needs to be a number", locale), HttpStatus.BAD_REQUEST);
                }
            }
            if(databaseCollection.isEmpty())
            {
                logger.warn("The database collection name is empty, using default value");
                databaseCollection = "myVerein";
            }

            if(!mongoIsAvailable(databaseHost, databasePortInt, databaseUser, databasePassword, databaseCollection))
            {
                logger.warn("The stated MongoDB is not available");
                return new ResponseEntity<>(messageSource.getMessage("init.message.settings.mongoNotAvailable", null, "The stated MongoDB is not available", locale), HttpStatus.BAD_REQUEST);
            }

            try
            {
                logger.debug("Temporarily storing information");
                settingsRepository.setClubName(clubName);
                settingsRepository.setDatabaseHost(databaseHost);
                settingsRepository.setDatabasePort(databasePort);
                settingsRepository.setDatabaseUser(databaseUser);
                settingsRepository.setDatabasePassword(databasePassword);
                settingsRepository.setDatabaseName(databaseCollection);
                settingsRepository.setRememberMeKey(rememberMeTokenKey);
            } catch (IOException e)
            {
                logger.warn("Unable to save settings.");
                return new ResponseEntity<>(messageSource.getMessage("init.message.settings.savingSettingsError", null, "Unable to save settings, please try again", locale), HttpStatus.INTERNAL_SERVER_ERROR);
            }
            return new ResponseEntity<>(messageSource.getMessage("init.message.settings.savingSettingsSuccess", null, "Successfully saved settings", locale), HttpStatus.OK);
        }
    }

    @RequestMapping(value = "superAdmin")
    public ResponseEntity<String> initSuperAdmin(@RequestParam String firstName,
                                                 @RequestParam String lastName,
                                                 @RequestParam String email,
                                                 @RequestParam String password,
                                                 @RequestParam String passwordRe,
                                                 Locale locale)
    {
        if(!settingsRepository.isInitSetup())
        {
            logger.warn("An initial setup API was used, even though the system is already configured.");
            return new ResponseEntity<>(messageSource.getMessage("init.message.admin.notAllowed", null, "You are not allowed to perform this action at the moment", locale), HttpStatus.BAD_REQUEST);
        } else if(firstName.isEmpty() || lastName.isEmpty() || email.isEmpty() || password.isEmpty() || passwordRe.isEmpty())
        {
            logger.warn("A required parameter of the super admin is empty or missing during initial configuration");
            return new ResponseEntity<>(messageSource.getMessage("init.message.admin.missingParameter", null, "A required parameter is empty or missing", locale), HttpStatus.BAD_REQUEST);
        } else if(!password.equals(passwordRe))
        {
            logger.warn("The password and the re-typed password do not match!");
            return new ResponseEntity<>(messageSource.getMessage("init.message.admin.passwordMatchError", null, "The password and the re-typed password do not match", locale), HttpStatus.BAD_REQUEST);
        } else
        {
            logger.debug("Creating a new initial user.");
            User superAdmin = new User();
            superAdmin.setFirstName(firstName);
            superAdmin.setLastName(lastName);
            superAdmin.setEmail(email);
            superAdmin.setPassword(password);

            logger.debug("Creating a new initial root division.");
            Division rootDivision = new Division(settingsRepository.getClubName(), null, superAdmin, null);

            //Saving changes and restarting context
            try
            {
                settingsRepository.setInitSetup(false);
                //This call is restarting the application.
                settingsRepository.saveSettings(superAdmin);
            } catch (IOException e)
            {
                logger.warn("Unable to save settings.");
                return new ResponseEntity<>(messageSource.getMessage("init.message.admin.savingSettingsError", null, "Unable to save settings, please try again", locale), HttpStatus.INTERNAL_SERVER_ERROR);
            }

            try
            {
                userRepository.save(superAdmin);
                divisionRepository.save(rootDivision);
            } catch (ConstraintViolationException e)
            {
                logger.warn("A database constraint was violated while saving the new super admin.");
                return new ResponseEntity<>(messageSource.getMessage("init.message.admin.constraintViolation", null, "A database constraint was violated while saving the new super admin", locale), HttpStatus.BAD_REQUEST);
            }
            return new ResponseEntity<>(messageSource.getMessage("init.message.admin.savingAdminSuccess", null, "Successfully saved the new super admin. The settings are now being saved and the application is restarted.", locale) , HttpStatus.OK);
        }
    }

    private boolean mongoIsAvailable(String databaseHost, int databasePort, String databaseUser, String databasePassword, String databaseCollection)
    {
        logger.debug("Creating mongo client to test connection");
        List<MongoCredential> credential = null;
        MongoClient mongoClient = null;
        if(!databaseUser.isEmpty() && !databasePassword.isEmpty())
        {
            credential = Arrays.asList(MongoCredential.createMongoCRCredential(databaseUser, databaseCollection, databasePassword.toCharArray()));
        }

        try
        {
            mongoClient = new MongoClient(new ServerAddress(databaseHost, databasePort),credential);

            //Checking if connection REALLY works
            List<String> databases = mongoClient.getDatabaseNames();
            if(databases == null)
            {
                logger.warn("The list of databases is null");
                return false;
            } else if(databases.isEmpty())
            {
                logger.info("The databases are empty");
                return true;
            } else
            {
                logger.debug("The database connection seems okay.");
                return true;
            }
        } catch (UnknownHostException e)
        {
            logger.warn("Unable to resolve mongoDB host: " + e.getMessage());
            return false;
        } catch (MongoException e)
        {
            logger.warn("Unable to receive list of present databases: " + e.getMessage());
            return false;
        } finally
        {
            if(mongoClient != null)
            {
                mongoClient.close();
            }
        }
    }
}

施泰勒德夫。米韦林。服务器模型SettingsRepository(在属性文件中检索和存储设置,并在设置更改时重新启动应用程序)

public class SettingsRepository
{
    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private SimpleMongoDbFactory mongoDbFactory;

    @Autowired
    private ApplicationContext applicationContext;

    private Properties settings;
    private Resource settingsResource;

    private final static String settingsFileName = "myVerein.properties";
    //Property names
    private final static String databaseName = "dbName";
    private final static String databaseHost = "dbHost";
    private final static String databasePort = "dbPort";
    private final static String databaseUser = "dbUser";
    private final static String databasePassword = "dbPassword";
    private final static String rememberMeKey = "rememberMeKey";
    private final static String clubName = "clubName";
    private final static String initSetup = "initSetup";

    private boolean changed;
    private boolean databaseChanged;

    private static Logger logger = LoggerFactory.getLogger(SettingsRepository.class);

    public Properties loadSettings() throws IOException
    {
        if(settings == null)
        {
            logger.debug("Loading settings file from classpath");
            settingsResource = new ClassPathResource(settingsFileName);
            changed = false;
            databaseChanged = false;
            return (settings = PropertiesLoaderUtils.loadProperties(settingsResource));
        } else
        {
            return settings;
        }
    }

    //Getter and setter removed

    public void saveSettings(User currentUser) throws IOException
    {
        saveSettings(loadSettings(), currentUser);
    }

    public void saveSettings(Properties settings, User currentUser) throws IOException
    {
        if(changed)
        {
            logger.debug("Saving settings to " + settingsResource.getFile().getAbsolutePath());
            settings.store(new FileOutputStream(settingsResource.getFile()), "Settings last changed " + (currentUser != null ? ("by " + currentUser.getEmail() + " (" + LocalDateTime.now().toString() + ")") : LocalDateTime.now().toString()));
            if(databaseChanged)
            {
                try
                {
                    mongoDbFactory.destroy();
                } catch (Exception e)
                {
                    System.err.println("Problem destroying factory");
                }
                ((ConfigurableApplicationContext) applicationContext).refresh();
            }
            this.settings = null;
        } else
        {
            logger.debug("No need to save the settings");
        }
    }
}

在InitController的第178行抛出异常,这意味着在重新加载对象之后以及在将对象保存到新控制器userRepository期间。保存(超级管理员)


共有1个答案

谭桐
2023-03-14

基于简单的异常,很难说为什么重载不起作用,但这里有一些提示:

>

  • 关于重启应用程序上下文,有一篇很好的文章

    http://jroller.com/Solomon/entry/reloading_a_spring_web_application

    你可以从那里得到一些它为什么会失灵的线索。

    使用上下文重新加载,您需要小心在应用程序关闭时正确关闭所有打开的资源。

    检查是否在应用程序上下文中正确关闭了Mongo连接。

    使用spring mongo关闭mongo连接的正确方法是什么?

    在你添加代码之后。很难理解,你想用这个实现什么。这需要你付出一定的努力才能让它正常工作,而且大部分的努力都将是徒劳的。

    不能在Spring上下文中重新加载特定的bean,但可以通过调用ApplicationContext refresh()重新加载整个上下文,之后将重新创建所有bean,包括控制器bean。所以这至少应该是一个独立的控制器,没有额外的功能。此外,您似乎假设可以更改mongo配置,同时使用旧的引用向mongo写入一些内容。。。Spring不是这样的。所以别这样。

  •  类似资料:
    • 问题内容: 这是一个非常基本的问题-但我无法通过在线搜索找到答案。 我正在使用python控制ArcGIS,并且有一个简单的python脚本,该脚本调用了一些预先编写的代码。 但是,当我对预写代码进行更改时,它似乎没有导致任何更改。我导入了此模块,并尝试刷新它,但是没有任何反应。 我什至将它调用的文件移到了另一个位置,脚本仍然可以正常工作。昨天我做的一件事是我将所有python文件都添加到sys路

    • 问题内容: 我有一个带有php include的Div Tag,该div用来填充该信息,我想要做的是使它每隔15秒调用一次,以便它可以在那里更新信息,而不必重新加载整个网页。我试图用JavaScript / jQuery做到这一点,但似乎无法正常工作 这是我在搜索一些内容后所拥有的,然后发生的是,它加载了Small.php,但不会每15秒刷新一次或更新信息。 请帮忙! 我应该添加所有应显示的php

    • 问题内容: 我只是很好奇,因为我已经在FragmentActivity中设置了Fragment选项卡,如何从FragmentActivity或Fragment本身重新加载片段,以清除并重新加载该选项卡。我本质上需要重新选择选项卡以替换片段时发生的相同事情。有一种简单的方法可以执行此操作并重新加载片段吗? 问题答案: 创建一个方法,该方法开始FragmentTransaction,分离片段,然后提交

    • 我们在内部云上安装了kafka broker。我们使用zookeeper找到实际的url,并在bootstrap.server配置中提供。现在的问题是,当代理重新启动内部云时,它会使用新的主机端口在动态分配的机器上重新启动。现在,我最初在生产者配置中给出的主机端口无效。 问题是如何在不重新启动的情况下重新加载此配置。 注意:我知道这是一个糟糕的设计主机代理,它可以在不同的机器上重新启动,但这就是现

    • 当用户从用户界面更改配置时,我想动态地重新加载log4j附加器(RollingFileAppender)。 我已经通过编程删除了追加器,并用新的配置值创建了新的追加器。在此之后,appender broked MaxBackupIndex和MaxFileSize无法正常工作。但是如果我更改了文件名(日志文件名),那么它可以正常工作。 能帮我解决这个问题吗?

    • 我在我的应用程序中使用导航栏,每次我选择一个项目时,它都会加载一个片段。 我能够使用相同的文本字段和按钮保存片段的状态,但有一个片段可以加载地图、添加标记、集群并执行。 每次我转到另一个菜单项并返回时,它都会重新加载所有内容,例如AsyncTask、Cluster、Markers。我如何停止此片段以不再重新创建地图并在返回时保存状态: Udate 1:我更新了代码,但问题仍然存在 主要活动: 主片