简体   繁体   English

具有默认用户的Spring MVC Web App

[英]Spring MVC Web App with Default user

I am developing a web app using Spring MVC and Hibernate that I hope to package up as a WAR file and distribute for users to deploy where needed. 我正在使用Spring MVC和Hibernate开发一个Web应用程序,我希望将其打包为WAR文件并分发给用户,以便在需要时进行部署。

The application will require the database connection details before deploying, can anyone advise on the best practice of how to do this? 该应用程序将在部署之前要求提供数据库连接详细信息,任何人都可以就如何做到这一点的最佳实践提出建议吗? currently my database.properties file is packaged as part of the WAR file, is there an easier way than asking the user to manually edit this file inside the WAR file or in the source and then expect them to build the war file themselves? 当前,我的database.properties文件打包为WAR文件的一部分,是否有比要求用户在WAR文件或源文件中手动编辑此文件然后期望他们自己构建war文件更简单的方法?

I would also like an easy way for users to create a single admin user on first deploy easily - is it best to just provide a sql script to create that or is there a way to include the functionality in the web app so on first deploy it creates the user? 我还想为用户提供一种简单的方法,使用户可以在首次部署时轻松地创建一个管理员用户-最好是仅提供一个sql脚本来创建该管理员,还是可以在Web应用程序中包含该功能,因此首先进行部署创建用户?

Thanks 谢谢

Since web applications are not focused to "mass production", I can't tell if something like that is possible. 由于Web应用程序不专注于“批量生产”,因此我无法确定是否可以进行此类操作。

You can make an SQL script containing all your CREATE statements limited by "IF NOT EXISTS" to avoid deleting existing data. 您可以制作一个包含所有受“ IF NOT EXISTS”限制的CREATE语句的SQL脚本,以避免删除现有数据。 Hibernate can execute a sql script at the moment of creating the SessionFactory, if Hibernate finds a file named "import.sql" located in the classpath root, Hibernate will execute it. Hibernate可以在创建SessionFactory时执行一个sql脚本,如果Hibernate在类路径根目录中找到一个名为“ import.sql”的文件,则Hibernate将执行该脚本。 Also you can always edit the database.properties of an application already deployed without re-packaging the WAR. 另外,您始终可以编辑已经部署的应用程序的database.properties,而无需重新打包WAR。

Try Liquibase, http://www.liquibase.org/ . 尝试使用Liquibase, http://www.liquibase.org/ It does not allow your users to setup database connection details but it allows you to manage the database schema (create and update the schema) and default data. 它不允许您的用户设置数据库连接详细信息,但允许您管理数据库架构(创建和更新架构)和默认数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM