我正在尝试让一个可以在我的机器上完美运行的应用程序在docker上运行,这是我的docker文件:
FROM openjdk:11-jre-slim
VOLUME /tmp
ADD someJar.jar someJar.jar
ADD lib lib
ADD config.properties config.properties
ENTRYPOINT ["java", "-javaagent:lib/aspectjweaver-1.9.2.jar",
"-javaagent:lib/spring-instrument-5.1.6.RELEASE.jar", "--module-path",
"lib/javafx-sdk-11.0.2", "--add-modules=javafx.controls", "-
Dprism.verbose=true", "-jar","someJar.jar"]
Run Code Online (Sandbox Code Playgroud)
我还尝试将其基于高山openjdk11版本,其结果相同:
FROM adoptopenjdk/openjdk11:alpine
VOLUME /tmp
RUN apk update && apk add libx11 mesa-gl gtk+3.0 && apk update
ADD someJar.jar someJar.jar
ADD lib lib
ADD config.properties config.properties
ENTRYPOINT ["java", "-javaagent:lib/aspectjweaver-1.9.2.jar", "-javaagent:lib/spring-instrument-5.1.6.RELEASE.jar", "--module-path", "lib", "--add-modules=javafx.controls", "-Dprism.verbose=true", "-jar","someJar.jar"]
Run Code Online (Sandbox Code Playgroud)
The lib folder contains the linux flavor of the openJFX runtime (.so files and .jar files). I am developing this on …
我正在开发一个Spring Web应用程序,我有一个具有Integer属性的实体,用户可以在使用JSP表单创建新实体时填写该属性.此表单调用的控制器方法如下:
@RequestMapping(value = {"/newNursingUnit"}, method = RequestMethod.POST)
public String saveNursingUnit(@Valid NursingUnit nursingUnit, BindingResult result, ModelMap model)
{
boolean hasCustomErrors = validate(result, nursingUnit);
if ((hasCustomErrors) || (result.hasErrors()))
{
List<Facility> facilities = facilityService.findAll();
model.addAttribute("facilities", facilities);
setPermissions(model);
return "nursingUnitDataAccess";
}
nursingUnitService.save(nursingUnit);
session.setAttribute("successMessage", "Successfully added nursing unit \"" + nursingUnit.getName() + "\"!");
return "redirect:/nursingUnits/list";
}
Run Code Online (Sandbox Code Playgroud)
validate方法只检查DB中是否已存在名称,因此我没有包含它.我的问题是,当我故意在现场输入文字时,我希望有一个很好的信息,例如"自动放电时间必须是一个数字!".相反,Spring返回了这个绝对可怕的错误:
Failed to convert property value of type [java.lang.String] to required type [java.lang.Integer] for property autoDCTime; nested exception is java.lang.NumberFormatException: For input string: "sdf"
Run Code Online (Sandbox Code Playgroud)
我完全理解为什么会发生这种情况,但我不能为我的生活弄清楚如何以编程方式用我自己的替换Spring的默认数字格式异常错误消息.我知道可以用于此类事情的消息源,但我真的想直接在代码中实现这一点.
编辑
正如所建议的,我在我的控制器中构建了这个方法,但我仍然得到Spring的"未能转换属性值..."消息:
@ExceptionHandler({NumberFormatException.class}) …
Run Code Online (Sandbox Code Playgroud) 我开发了一个应用程序,用作单独的 Web 应用程序的通信服务。我有 0 个问题“dockerizing”了网络应用程序,但该服务被证明是一场噩梦。它基于 JavaFX,用户可以在配置文件中设置一个属性,使应用程序不会初始化任何窗口、菜单、容器等。这种“无头”模式(不确定是否真的headless...) 有效地将服务应用程序变成了后台服务。让我先说一下,该应用程序在我的 Windows 10 机器上运行时绝对完美无瑕,并且我已经将它部署在其他几台机器上(全部非 dockerized),没有任何问题。
这是我想出的dockerfile:
FROM openjdk:13.0.1-slim
RUN apt-get update && apt-get install libgtk-3-0 libglu1-mesa -y && apt-get update
VOLUME /tmp
ADD Some_Service-0.0.1-SNAPSHOT.jar Some_Service-0.0.1-SNAPSHOT.jar
ADD lib lib
ADD config.properties config.properties
ENTRYPOINT ["java", "--module-path", "lib/javafx-sdk-13", "-jar", "Some_Service-0.0.1-SNAPSHOT.jar"]
Run Code Online (Sandbox Code Playgroud)
然后我使用这个命令来构建容器:
docker run -t --name Some_Service -e DISPLAY=192.168.1.71:0.0 -e SERVICE_HOME= --link mySQLMD:mysql some_service
Run Code Online (Sandbox Code Playgroud)
假设 VcXsrv 在我的 PC 上运行,该应用程序可以正确启动,尽管它在首次启动时会发出以下警告:
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Prism-ES2 Error : GL_VERSION …
Run Code Online (Sandbox Code Playgroud) 我正在尝试改进我的Spring MVC应用程序,以使用全局异常处理程序来捕获所有控制器中的各种持久性异常.这是用户尝试保存新的StrengthUnit对象时运行的控制器代码.所有验证都可以正常工作,并且在抛出PersistenceException时正确返回表单,并在名称字段下面显示错误消息.结果页面还正确包含strengthUnit属性,并且能够将字段(此实体只有一个名称字段)绑定到表单:
@RequestMapping(value = {"/newStrengthUnit"}, method = RequestMethod.POST)
public String saveStrengthUnit(@Valid StrengthUnit strengthUnit, BindingResult result, ModelMap model) throws Exception
{
try
{
setPermissions(model);
if (result.hasErrors())
{
return "strengthUnitDataAccess";
}
strengthUnitService.save(strengthUnit);
session.setAttribute("successMessage", "Successfully added strength unit \"" + strengthUnit.getName() + "\"!");
}
catch (PersistenceException ex)
{
FieldError error = new FieldError("strengthUnit", "name", strengthUnit.getName(), false, null, null,
"Strength unit \"" + strengthUnit.getName() + "\" already exists!");
result.addError(error);
return "strengthUnitDataAccess";
}
return "redirect:/strengthUnits/list";
}
Run Code Online (Sandbox Code Playgroud)
我试图使用它作为一个起点来合并我构建的全局异常处理程序,我不明白如何调用该处理程序并返回具有相同模型和绑定结果的同一页面.我尝试了一些非常丑陋的自定义异常只是为了尝试理解机制并让处理程序返回我以前的同一页面,我无法让它工作.
这是我构建的自定义异常:
public class EntityAlreadyPersistedException extends Exception
{
private …
Run Code Online (Sandbox Code Playgroud) 我已经决定我已经受够了 Eclipse 的缓慢并把所有东西都移到了 VSCode。我安装了 java 扩展包以及 Lombok 扩展。
我的项目在 Eclipse 中运行良好,虽然它运行良好,但 VSCode 发现了数千个明显与未找到 Lombok 生成的 getter/setter 方法相关的错误。我的解决方案由两个项目组成,它们都依赖于一个类库(第三个项目),该类库依赖于 Lombok 注册。
如何摆脱这些错误/使 Lombok 在 VSCode 中正常工作?
如果选定的选项是jQuery的第一个(占位符),则我已经成功地将不同的样式应用于普通的select元素,如下所示:
<script type="text/javascript">
$(document).ready
(
function ()
{
$('select').each(function (index, value)
{
if($(this).val()==="")
{
$(this).css('font-style', 'italic');
$(this).css('color', '#636c72');
$(this).children().css('font-style', 'normal');
}
else
{
$(this).css('font-style', 'normal');
$(this).css('color', 'black');
$(this).children().css('font-style', 'normal');
}
});
}
);
</script>
Run Code Online (Sandbox Code Playgroud)
但是,由于其中包含的条目数量庞大(可能是数千个),并且有必要使用文本搜索来缩小条目范围,因此我的某些表格正在使用bootstrap-select组件。这些组件会产生更复杂的HTML,并且以上代码根本无法工作。
我试图找到一种方法来应用与普通选择相同的逻辑:如果所选的选项是第一个选项,则以斜体和不同的颜色设置输入的样式。这是此类select的示例:
<select class="form-control selectpicker" id="medFilter" name="medFilter" th:value="${medFilter}"
onchange="this.form.submit()" data-live-search="true" title="Select Med">
<option value="">Search Med</option>
<option th:each="med : ${meds}" th:value="${med.id}"
th:text="${med.toString()}" th:selected="${med.id == medFilter}">
</option>
</select>
Run Code Online (Sandbox Code Playgroud)
有没有人能够做到这一点?
在我的应用程序中,我在用户和首选项实体之间存在多对多关联.由于连接表需要一个额外的列,我不得不将其分解为2个一对多关联:
用户实体:
@OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true)
public Set<UserPreference> getPreferences()
{
return preferences;
}
Run Code Online (Sandbox Code Playgroud)
偏好实体:
@OneToMany(mappedBy = "preference", fetch = FetchType.EAGER)
public Set<UserPreference> getUserPreferences()
{
return userPreferences;
}
Run Code Online (Sandbox Code Playgroud)
UserPreference实体:
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
public User getUser()
{
return user;
}
public void setUser(User user)
{
this.user = user;
}
@ManyToOne
@JoinColumn(name = "preference_id", nullable = false)
public Preference getPreference()
{
return preference;
}
public void setPreference(Preference preference)
{
this.preference = preference; …
Run Code Online (Sandbox Code Playgroud) 我正在通过将我在 eclipse 上所做的项目移到它来尝试 vsCode。我在 eclipse 中为这个项目有一个运行配置,它有以下 JVM 参数:
--module-path lib/javafx-sdk-13/lib --add-modules=javafx.controls
Run Code Online (Sandbox Code Playgroud)
当然,这个“lib”文件夹及其内容跟随到新的 vsCode 项目文件夹中,但我不知道将这些 JVM 参数放在 vsCode 中的什么位置,本质上相当于 eclipse 的运行配置。我尝试将它们放在 launch.json 文件的 args 部分,但没有成功。
如果这有所作为,我将使用 spring boot 仪表板来启动项目。
这是我的 launch.json 文件:
{
"configurations": [
{
"type": "java",
"name": "Spring Boot-BudgetApplication<budget>",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"mainClass": "com.someone.budget.BudgetApplication",
"projectName": "budget",
"args": ["--module-path","lib/javafx-sdk-13/lib","--add-modules=javafx.controls"]
}
]
Run Code Online (Sandbox Code Playgroud)
}
谢谢
我使用Netbeans为我的JavaFX应用程序生成模板.它生成了一个POM.xml,构建部分似乎过于复杂.此外,它每次编译项目时解包所有依赖项,每次需要3分钟.以下是POM.xml文件的相关部分:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<organization>
<name>MDenis</name>
</organization>
<dependencies>
<!--SPRING-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<!--HIBERNATE-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.10.Final</version>
</dependency>
<!--HSQLDB-->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<!--LOMBOK-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--LOG4J2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory> …
Run Code Online (Sandbox Code Playgroud) 升级到 Spring Boot 2.4 后,我的 Web 应用程序不再启动。它抛出以下错误:
Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码来更改上下文路径,我的研究指出这是“罪魁祸首”(更改上下文路径):
@Bean
public ServletWebServerFactory servletContainer()
{
String tomcatPort = environment.getProperty("tomcatPort");
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.setPort(tomcatPort != null ? Integer.parseInt(tomcatPort) : 8080);
tomcat.setContextPath("/Carbon");
tomcat.setBaseDirectory(new File(System.getenv("MDHIS3_HOME")));
setTomcatProtocol(tomcat);
return tomcat;
}
Run Code Online (Sandbox Code Playgroud)
我有以下方法,我可以看到它可以用来传递 defaultServletName 但我不知道我应该传递什么值:
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
{
configurer.enable();
}
Run Code Online (Sandbox Code Playgroud)
这在 Spring Boot 2.3.4 上运行良好。我在那里传递什么值?是主控制器的名字吗?
java ×7
javafx ×3
spring ×3
spring-boot ×3
docker ×2
build ×1
contextpath ×1
controller ×1
css ×1
exception ×1
hibernate ×1
html ×1
java-11 ×1
jointable ×1
jquery ×1
lombok ×1
many-to-many ×1
maven ×1
message ×1
nvidia ×1
opengl ×1
openjfx ×1
placeholder ×1
replace ×1
servlets ×1
tomcat ×1
updates ×1