有没有办法获得Java Bean字段的Object数组?我有一些表示数据库表 (Hibernate) 的 bean 类,我需要从它们中检索 jtable 模型的对象数组,但似乎唯一的方法是为每个类的每个字段调用 getXXX 方法 - 很多要做的工作。
我需要将具有嵌套对象(深)的对象的属性映射到 DTO 对象。实际上,我想将复杂对象缩小为具有甚至嵌套对象的所有属性的简单 DTO。我试过 BeanUtils 但这也不做深复制。所以我正在探索 Dozer 来实施解决方案。但即使是 Dozer 也在映射一级属性而不是深层嵌套对象属性。
这是我的课程:
public class Child1 {
private String name = "MyName";
private String address = "ABC";
public TestDTO dto = new TestDTO("50", "USA");
public TestDTO getDto() {
return dto;
}
public void setDto(TestDTO dto) {
this.dto = dto;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
} …Run Code Online (Sandbox Code Playgroud) 我收到以下错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'preTransactionHandlerPool' defined in class com.fg.transbridge.processor.spring.ContextConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException
Run Code Online (Sandbox Code Playgroud)
我已经有了preTransactionHandlerPool豆子。
@Bean(name = "preTransactionHandlerPool")
public ThreadPoolTaskExecutor preTransactionHandlerPool() {
LOGGER.info("Initializing preTransactionHandlerPool");
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(preTransCorePoolSize);
threadPoolTaskExecutor.setMaxPoolSize(preTransMaxPoolSize);
threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(preWaitForCompleteShutDown);
LOGGER.debug("Initiated preTransactionHandlerPool");
return threadPoolTaskExecutor;
}
Run Code Online (Sandbox Code Playgroud)
那可能是什么原因?非常感谢您的帮助。
谢谢你
我有一个 Spring Security 角色层次结构,设置如下:
ROLE_ADMIN > ROLE_MANAGER
ROLE_MANAGER > ROLE_USER
ROLE_USER > ROLE_GUEST
Run Code Online (Sandbox Code Playgroud)
我发现自己需要创建一个 VetoableChangeListener,它可以根据角色否决 PropertyChangeEvents(由于那些愚蠢的 Legacy Design 问题之一)。
因此,在我的 vetoableChange() 方法中,需要根据层次结构否决更改。例如,某个字段不能被定义的层次结构中 ROLE_MANAGER 之下的任何角色更改,因此如果 ROLE_USER 尝试更改它,则会引发 PropertyVetoException。
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
String role = SecurityContextHolder.getContext().getAuthentication().getRoles().get(0);
String propertyName = evt.getPropertyName();
String requiredRole = getRequiredRole(propertyName);
// determine if the current role is equal to or greater than
// the required role, throw PropertyVetoException if not
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以提供帮助吗?
我正在查看http://docs.oracle.com/javase/8/javafx/api/javafx/beans/property/SimpleObjectProperty.html,我有点困惑。
SimpleObjectProperty我可以使用第三个构造函数创建一个,
SimpleObjectProperty(Object bean, String name, T initialValue)
Run Code Online (Sandbox Code Playgroud)
在 Clojure 中如下:(def sop (SimpleObjectProperty. 5 "mysop" 6))
这将创建一个SimpleObjectPropertyBean value = 5(类型为java.lang.Long)和非 Bean value = 6(类型为 )的 Bean (java.lang.Long)。
为什么有两个不同的“价值观”?在这种情况下,“Bean”的用途是什么?我应该使用哪一个?我正在尝试封装一个可以在其上设置侦听器的通用 Clojure 对象,因此我认为它要么是这个,要么ObjectPropertyBase是层次结构中的一个并且可以直接实例化。
我一直在慢慢地学习 Java,以了解如何在 Clojure 中使用 JavaFX,但这一个令人困惑。
谢谢!:)
我有一个 Spring @Configuration 类,如下所示:
@Configuration
public class ExecutorServiceConfiguration {
@Bean
public BlockingQueue<Runnable> queue() {
return ArrayBlockingQueue<>(1000);
}
@Bean
public ExecutorService executor(BlockingQueue<Runnable> queue) {
return ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, queue);
}
@PreDestroy
public void shutdownExecutor() {
// no executor instance
}
}
Run Code Online (Sandbox Code Playgroud)
我还想指定一种@PreDestroy关闭 ExecutorService 的方法。但是,该@PreDestroy方法不能有任何参数,这就是为什么我无法将executorbean 传递给该方法以关闭它的原因。指定 destroy 方法也@Bean(destroyMethod = "...")不起作用。它允许我指定现有的shutdownor shutdownNow,但不能指定我打算使用的自定义方法。
我知道我可以直接实例化队列和执行器,而不是作为 Spring bean,但我宁愿这样做。
我的目标是用 Spring 创建一个 Web 服务器。它必须实现多租户,如果您不使其动态(添加、删除、更改),它会非常有效。Spring中是否可以更新数据源bean?
我的代码:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) throws IOException {
SpringApplication.run(MyApplication.class, args);
}
//Multitenancy
@Bean
public DataSource dataSource(){
//implements AbstractRoutingDataSource
CustomRoutingDataSource customDataSource = new CustomRoutingDataSource();
//logic here
return customDataSource;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过的:
CustomRoutingDataSource c = context.getBean(CustomRoutingDataSource.class);
c.setTargetDataSources(CustomRoutingDataSource.getCustomDatasources());
Run Code Online (Sandbox Code Playgroud)
它更新了bean(?)但不更新Spring的数据源,如果使用此方法添加,数据库连接仍然丢失。
所以我在尝试传递String值时遇到问题.
字符串值通过登录页面作为用户名输入.
然后,JSF调用Bean来验证登录信息,然后进入另一个JSF页面.
我想知道如何将用户名传递给新的JSF页面.谢谢.
我是FX的新手,对Java不是那么新,所以请耐心等待!我所拥有的是一个使用由ObservableList支持的JavaFX TableView的简单应用程序.
当我第一次启动应用程序时,我生成另一个Thread(来自Application的start方法)来监听对日志文件的更改,并将另一个元素添加到ObservableList中,以便在TableView中可以立即看到该行.我认为在窗口中包含一个包含ObservableList当前大小的Label是有益的.我试图将Label的textProperty绑定到ObservableList的大小.我的第一次尝试产生了:
tableSizeLabel.textProperty().bind(Bindings.size((tableView.getItems())).asString());
但我相信我误解了Bindings API.我意识到ObservableList.size()返回一个常规的int而不是ObservableValue,它甚至可以工作,但我认为Bindings类有一个静态方法为我创建一个.
后端模型将列表作为静态变量包含在内(我省略了listen-for-changes部分):
public class LogFileListener implements Runnable {
private static final ObservableList<SNMPTrap> model = FXCollections.observableArrayList();
@Override
public void run() {
String line = null;
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileLocation)))) {
while ((line = br.readLine()) != null) {
model.add(parseTrap(line));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static ObservableList<SNMPTrap> getModel() {
return model;
}
Run Code Online (Sandbox Code Playgroud)
}
应用类:
public class TableDisplay extends Application {
@Override
public void start(Stage stage) throws Exception {
new …Run Code Online (Sandbox Code Playgroud) javabeans ×10
java ×8
spring ×4
javafx ×2
abstract ×1
binding ×1
class ×1
clojure ×1
clone ×1
datasource ×1
dozer ×1
hibernate ×1
javafx-2 ×1
jsf ×1
mapping ×1
maven ×1
predestroy ×1
spring-boot ×1
tablemodel ×1