我使用Spring boot 1.3.1及其嵌入式Tomcat容器.我是Spring boot的新手.
我作为一个独立的jar运行java -jar myApp.jar.
我在以下位置设置了日志文件和tomcat位置application.properties:
logging.file=myApp.log
server.tomcat.basedir=./tomcat
Run Code Online (Sandbox Code Playgroud)
但是,应用程序经常退出.在日志文件中没有提供退出的信息.
所以我的问题是如何启用一些更详细的应用程序日志记录,或者是否有一些方法可用于在这种情况下解决问题?
谢谢!
我为患者所代表的患者提供这些属性.我想知道命名他们的最佳做法是什么?
首先想到的是将它们命名为:
boolean isInLactationPeriod;
boolean isPregnant;
boolean isPreparingPregnant;
boolean hasSufferedLowBloodGlucoseRecently;
boolean hasComplications;
Run Code Online (Sandbox Code Playgroud)
但是我也遇到过这样的建议:java属性不应该是带有前导的名称/ has,而是将它们留给getter/setter方法,例如
boolean pregnant;
boolean isPregnant() {
return pregnant;
}
Run Code Online (Sandbox Code Playgroud)
哪一个更好?
Spring Boot中有三个启动器:JarLauncher/PropertiesLauncher/WarLauncher.对于可执行jar,默认情况下将使用JarLauncher.现在我想使用PropertiesLauncher,以便我可以使用外部类路径.我怎么能指定那是spring boot gradle插件?
根据这个doc D.3.1 Launcher清单的 D3.1 ,我可以在MANIFEST.MF中指定主类,如下所示:
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.mycompany.project.MyApplication
Run Code Online (Sandbox Code Playgroud)
但是,在Spring Boot Gradle中,以下代码片段实际指定了Start-Class,而不是Main-Class:
springBoot {
mainClass = "com.sybercare.HealthServiceApplication"
}
Run Code Online (Sandbox Code Playgroud)
我是否需要手动创建MANIFIEST.MF或者有更好的方法来执行此操作?
谢谢!
我必须将我的类定义映射到现有数据库,其中日期字段存储为varchar.
例如
class A {
@Column
Date birth;
}
Run Code Online (Sandbox Code Playgroud)
如何对出生属性进行注释,以便将其正确映射到数据库varchar?
谢谢!
我想在存储库接口中执行类似的操作(在Spring Data JPA中):
interface myRepository extends JpaRepository<A, Long> {
@Query("select a from A a where a.x = :x")
A findFirstBySomeCondition(int x);
}
Run Code Online (Sandbox Code Playgroud)
但我只需要第一个结果.(编辑:实际查询条件非常复杂,所以我更喜欢使用@Query代替findFirst或findTop ...)
我不想使用标准api,因为它很冗长.
我不想使用本机查询,因为我将不得不手动编写查询字符串.
那么,考虑到上面的限制要求,是否还有解决方案?
谢谢!
我有一些 Jpa 存储库和几个实体类。我需要为我的实体之一创建一个辅助对象。在该帮助程序中,我使用 @Autowire 来访问 Jpa 存储库。
@Entity
class A {
@Transient
Helper helper;
...
}
class Helper {
A a;
@Autowired
CRepository repo;
public Helper(A a) {
this.a = a;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,存储库始终为空。我尝试过使用 SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this) 和 @Configurable,但它们都失败了。有人能为我提供一些提示吗?
顺便说一句,A 在剩余控制器内实例化。
谢谢!。
我今天早上来到这个现象,equals方法中Set没有检查元素的值是否相等List.这不符合java doc.
Set<MyClass> s1 = new HashSet<>();
Set<MyClass> s2 = new HashSet<>();
Set<MyClass> s3 = new HashSet<>();
Set<MyClass> s4 = new HashSet<>();
List<MyClass> l1 = new ArrayList<>();
List<MyClass> l2 = new ArrayList<>();
MyClass o1 = new MyClass();
MyClass o2 = new MyClass();
// **this gives false, and does not call MyClass.equals().**
s1.add(o1);
s2.add(o2);
boolean setCompareWithDifferentObjects = s1.equals(s2);
// this gives true, and also does not call MyClass.equals().
s3.add(o1);
s4.add(o1);
boolean setCompareWithSaveObjects = s3.equals(s4);
// …Run Code Online (Sandbox Code Playgroud)