我有一个由FindBugs报告的错误,但我知道更好:)请参阅以下示例:
public class MyClass extends BaseClass {
@CustomInjection
private Object someField;
public MyClass() {
super();
someField.someMethod(); // Bug is here because FindsBugs thinks this is always null
}
}
Run Code Online (Sandbox Code Playgroud)
在我的BaseClass构造函数中,我使用正确的对象注入带有@CustomInjection批注的所有字段,因此我的注释字段在我的情况下不为空.
我不想用'suppresswarnings'来抑制警告,因为这会使代码混乱很多.我宁愿做像FindBugs这样一个过滤器解释在这里,但我无法弄清楚如何筛选具有一定的界面注释字段错误.我也不想过滤所有空错误警告.我认为应该是这样的:
<Match>
<Bug code="UR">
<Field annotation="CustomInjection">
</Match>
Run Code Online (Sandbox Code Playgroud) 我试图在一个Linux机器上的不同用户下运行多个jvms(包括tomcat).我没有看到太多问题,但在catalina.out我一直看到这个:
May 30, 2014 1:16:16 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7626 ms
May 30, 2014 1:16:37 PM java.util.prefs.FileSystemPreferences$2 run
WARNING: Could not create system preferences directory. System preferences are unusable.
May 30, 2014 1:16:55 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode
WARNING: Could not lock System prefs. Unix error code -158097957.
May 30, 2014 1:16:55 PM java.util.prefs.FileSystemPreferences syncWorld
WARNING: Couldn't flush system prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
Run Code Online (Sandbox Code Playgroud)
我做了一些挖掘/阅读并推断出以下内容:
具有root访问权限的管理员必须创建系统首选项目录 /etc/.java/.systemPrefs with drwxr-xr-x access.
Java正在寻找/etc/.java/.systemPrefs/.system.lock和/etc/.java/.systemPrefs/.systemRootModFile
手动创建上述文件(使用"touch"创建空文件)及其包含的目录应该修复.对文件的544权利应该是,对其目录的权限应该是755 …
我想用javascript检测本机android浏览器(安装在每个Android手机上的浏览器).
我应该在useragent中寻找什么?
我正在开始一个新项目,我需要使用SonarQube,我想使用Lombok,我已经在Eclipse中配置它,一切正常,除了静态分析.
@Data类时,所有字段都被报告为Unused private field.@Getter(lazy=true):当我使用此批注我得到的Redundant nullcheck of value known to be non-null 看@Getter(懒惰=真)(这是关系到编译后的代码).我认为一个可能的解决方案是delombok项目,编译并运行Sonar.
类似问题SonarQube Jira:
(@SuppressWarnings("PMD.UnusedPrivateField")解决方案不适用于最新SonarQube 4.2)
我怎么解决这个问题?
我正在使用单例测试容器来运行多个集成测试,如下所示:
@SpringBootTest(webEnvironment = RANDOM_PORT)
public abstract class BaseIT {
static final PostgreSQLContainer<?> postgreSQLContainer;
static {
postgreSQLContainer =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:13"))
.withDatabaseName("test")
.withUsername("duke")
.withPassword("s3cret")
.withReuse(true);
postgreSQLContainer.start();
}
@DynamicPropertySource
static void datasourceConfig(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgreSQLContainer::getJdbcUrl);
registry.add("spring.datasource.password", postgreSQLContainer::getPassword);
registry.add("spring.datasource.username", postgreSQLContainer::getUsername);
}
}
Run Code Online (Sandbox Code Playgroud)
然后从测试底座延伸出来
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class SecondApplicationIT extends BaseIT{
@Autowired
private TestRestTemplate testRestTemplate;
@Autowired
private TodoRepository todoRepository;
@AfterEach
public void cleanup() {
this.todoRepository.deleteAll();
}
@Test
void contextLoads() {
this.todoRepository.saveAll(List.of(new Todo("Write blog post", LocalDateTime.now().plusDays(2)),
new Todo("Clean appartment", LocalDateTime.now().plusDays(4))));
ResponseEntity<ArrayNode> result = …Run Code Online (Sandbox Code Playgroud) 假设我有一张地图:
<map name="externalIds" table="album_external_ids">
<key column="album_id" not-null="true"/>
<map-key-many-to-many class="Major" column="major_id"/>
<element column="external_id" type="string" not-null="true"/>
</map>
Run Code Online (Sandbox Code Playgroud)
如何制作HQL,表示“选择映射键ID ==:foo和映射值==:bar的实体”?
我可以使用来加入它,select album from Album album join album.externalIds ids
但是我将如何引用id的键和值呢?ids.key.id =:foo和ids.value =:bar不起作用,并且休眠文档对此主题保持沉默。
天真的方法不起作用:
select album
from Album album
join album.externalIds externalId
where index(externalId).id = :foo and externalId = :bar
Run Code Online (Sandbox Code Playgroud)
和
select album
from Album album
join album.externalIds externalId
join index(externalId) major
where major.id = :foo and externalId = :bar
Run Code Online (Sandbox Code Playgroud) 我已经使用Maven实现了Liquibase。我们当前使用的是单个数据库(db2),但是现在我们需要向应用程序中添加一个具有不同对象的新数据库。
我已经看到我可以在Maven中定义一个新的配置文件,但是我找不到如何区分在哪个数据库上创建哪些对象的方法。
这个问题有方法解决吗?我可以使用liquibase支持2个具有不同对象的不同数据库吗?
我想创建一个Spring BeanFactoryPostProcessor,它将bean添加到当前的ApplicationContext中.
我有很多Web服务定义,我spring-ws-config.xml希望尽可能减少.
配置如下:
<bean id="menu"
class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"
lazy-init="true">
<property name="schemaCollection">
<bean
class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
<property name="inline" value="true" />
<property name="xsds">
<list>
<value>classpath:xsd.xsd</value>
</list>
</property>
</bean>
</property>
<property name="portTypeName" value="portType" />
<property name="serviceName" value="serviceName" />
<property name="locationUri" value="/endpoints" />
</bean>
Run Code Online (Sandbox Code Playgroud)
因此,我使用以下bean定义创建一个@Configuration类:
@Bean
@Lazy
public DefaultWsdl11Definition webService() throws IOException {
logger.info("Creating Web Service");
DefaultWsdl11Definition toRet = new DefaultWsdl11Definition();
toRet.setPortTypeName("portType");
toRet.setServiceName("serviceName");
CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection();
collection.setInline(true);
collection.setXsds(new Resource[] { new ClassPathResource("path1") });
collection.afterPropertiesSet();
toRet.setSchemaCollection(collection);
toRet.setLocationUri("/endpoints");
return toRet;
} …Run Code Online (Sandbox Code Playgroud) 我想从 ldap 搜索特定用户详细信息。所以我写下了以下代码来检索用户详细信息,但它返回用户对象列表。基本上我只想要人对象而不是人对象列表。使用 LDAP 模板检索 IM。我如何修改此代码以使其返回 person 对象?
public void searchByFirstName(String loginId) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "Person"));
filter.and(new EqualsFilter("cn", loginId));
List list = ldapTemplate.search("",
filter.encode(),
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs) throws NamingException {
return attrs.get("sn").get();
}
});
}
Run Code Online (Sandbox Code Playgroud) while(true) {
if(((d.multiply(e)).mod(phi1)).equals(BigInteger.ONE))
break;
d.add(BigInteger.ONE);
}
Run Code Online (Sandbox Code Playgroud)
我的程序中有以下代码,这意味着
while(true) {
if((d*e)%phil==1)
break;
d++;
}
Run Code Online (Sandbox Code Playgroud)
这里e=17,phil=12816并d=1开始.
但即使在等待很长时间之后,循环仍在执行.可能是什么错误?
java ×5
biginteger ×1
dictionary ×1
eclipse ×1
findbugs ×1
hibernate ×1
hql ×1
html ×1
javascript ×1
jquery ×1
ldap ×1
linux ×1
liquibase ×1
lombok ×1
maven ×1
permissions ×1
root ×1
sonarqube ×1
spring ×1
spring-3 ×1
spring-boot ×1
spring-ldap ×1
tomcat ×1