是否相当于:
<jsp:setProperty name="beanName" property="*"/>
Run Code Online (Sandbox Code Playgroud)
对于servlet?
是否会使用请求参数从servlet内部自动填充bean?我正在重构一个仅支持JSP的应用程序,并希望将一些代码移动到servlet.由于一系列悲剧性原因,我们现在无法使用任何框架来使这更容易.
@Component只要配置了上下文组件扫描,只使用注释就能创建spring bean是否正确?
使用带有Java 6的spring 3.0.5.
我的测试用例是:
@ContextConfiguration(locations={"classpath:spring-bean.xml"})
public class ServerServiceUnitTest extends AbstractJUnit4SpringContextTests {
@Autowired
private ServerService serverService;
@Test
public void test_server_service() throws Exception {
serverService.doSomething();
//additional test code here
}
}
Run Code Online (Sandbox Code Playgroud)
该spring-bean.xml文件包含:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
</beans>
Run Code Online (Sandbox Code Playgroud)
我想成为一个bean的课程是:
@Component("ServerService")
public class ServerServiceImpl implements ServerService {
private static final String SERVER_NAME = "test.nowhere.com";
//method definitions.....'
}
Run Code Online (Sandbox Code Playgroud)
那不足以让spring实例化ServerServicebean并进行自动装配吗?
我得到的错误是:
由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型[serversystem.ServerService]的匹配bean:期望至少有1个bean符合此依赖项的autowire候选者.依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
我确定我错过了一些简单的事情.
使用下面的例子,Joshua Bloch的防御性复制技术是否有优雅的Java实现?nullChecking确实是我认为的问题,但也许有一种更简单的方法来实现防御性复制.
public class Audit {
private Date dateCompleted;
...
public Audit() {
super();
}
//defensive copy of dateCompleted
public final Date getDateCompleted() {
if (dateCompleted != null){
return new Date(dateCompleted.getTime());
}else{
return null;
}
}
public final void setDateCompleted(Date dateCompleted) {
if (dateCompleted != null){
this.dateCompleted = new Date(dateCompleted.getTime());
}else{
this.dateCompleted = null;
}
}
...
}
Run Code Online (Sandbox Code Playgroud) 我需要将外部lib类连接到我的bean,以便将其用作单例.
.xml配置:
<bean id="myBean" class="com.my.MyBean">
<property name="someLib" value="com.ExternalBean" />
</bean>
Run Code Online (Sandbox Code Playgroud)
java bean:
@Service
public class MyBean {
@Autowired
private ExternalBean externalBean;
public void setExternalBean(ExternalBean externalBean) {
this.externalBean = externalBean;
}
Run Code Online (Sandbox Code Playgroud)
此外,我externalBean在公共方法中使用有线变量,以便不在每个方法调用中实例化它.问题是它null.
我是否正确连接豆?什么是错误.
例如,我有这个代码:
<jsp:useBean id="dog" class="Dog" scope="application">
<jsp:setProperty name="dog" property="breed" value="House Dog !!!"/>
</jsp:useBean>
Run Code Online (Sandbox Code Playgroud)
我知道它是如何工作的.但是,有时候,我在这里更改了一些代码,例如:"dog"到"newDog",我会遇到错误或未经编辑的结果(和我一起).
请告诉我如何将上面的代码生成到Java中.(也许只是一个主要想法)
谢谢 :)
我试图在java bean中混洗一组双打,以便在JSP文件中使用.
在我的java bean的默认构造函数中,我有:
amounts = new double[] {0.5, 1, 1.5, 2, 2.5. 3, 3.5, 4};
Collections.shuffle(Arrays.asList(amounts));
Run Code Online (Sandbox Code Playgroud)
我可以调用bean的方法,但由于某种原因,amount数组保持不变,所以它要么不是shuffling,要么默认构造函数没有执行.没有错误被抛出,所以我相信它可能是构造函数没有执行但我无法弄清楚为什么.
在我的JSP中我使用:
<jsp:useBean id="myBean" class="logic.logicBean" scope = "session" />
Run Code Online (Sandbox Code Playgroud)
我想这样做,默认构造函数会执行,这是错误的吗?
我正在使用Java Bean在JSP中创建一个CRUD应用程序.我想询问IDE或任何附件中是否有内置功能来自动生成DB表的CRUD功能?
类似于setter和accessor方法可以由IDE生成.我知道我们可以使用像Spring这样的很多框架来获取CRUD,但对于一个简单的应用程序,这可能只使用JSP和java bean吗?
根据标准命名约定,必须使用get,set,is(可用于布尔属性而不是get)以及其他方法(所谓的访问器方法和mutator方法)来访问类属性.
这不会打破封装规则吗?毕竟,如果每个私有财产都有一个getter/setter,那么它是否会被封装?
或者你必须为每个房产至少使用一个?要么设置,得到,要么两者都有,但从来没有?
Domino 8.5.3 FP5,Designer 9.0.1.
我有一个空的xpage只包含以下复选框.我无法使其可编辑.它显示正确的值,但显示为已禁用.
<xp:checkBox text="Label" id="checkBox1" uncheckedValue="true"
checkedValue="false"
value="#{javascript:jBeanConfigSupport.validationEnabledTxt}">
</xp:checkBox>
Run Code Online (Sandbox Code Playgroud)
如果我删除绑定到Java bean,所有运行正常.这是Java bean代码(部分)
private boolean isValidationEnabled=true;
public String getValidationEnabledTxt() {
return String.valueOf(isValidationEnabled);
}
public void setValidationEnabledTxt(String onOff) {
isValidationEnabled=Boolean.parseBoolean(onOff);
}
public void setValidationEnabledTxt(boolean onOff) {
isValidationEnabled=onOff;
}
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
为什么afterPropertiesSet的 InitializingBean需要的时候,我们也有定制init()
@Bean(initMethod = "init")或@PostConstuct?我可以用一个做什么而不做另一个做什么?我何时应该使用一个而不是另一个.在所有属性自动装配后触发所有回调.