我有一个相当天真的问题.我们可以使用核心java注入依赖关系,就像我们使用Spring框架注入一样吗?
现在,我做这样的事情:
在web.xml中:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
spring applicationcontext.xml:
<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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="mybean" class="com.test.app.MyService" />
</beans>
Run Code Online (Sandbox Code Playgroud)
我将使用注入的bean的类:
public class MyResource {
@Autowired
private MyService mybean;
public MyResponse doService(MyRequest req) {
mybean.doBusiness(req);
}
}
Run Code Online (Sandbox Code Playgroud)
}
那么,有没有办法可以使用核心java进行这种依赖注入?我一直在读CDI,但不太懂.此外,它也感觉它不是直接替代Spring所做的事情.
如果我错了,请帮助并纠正我.
我需要帮助.我正在开展一个项目,我有多个页面和多个表格; 每个页面都有一个表单.我只需要能够将值从一个jsp传递到另一个jsp.我该怎么办?
我是Spring MVC的新手.我使用的是2.5.6弹簧.
这是我的设计:
formPage1.jsp - > Controller1 - > formPage2a.jsp - > Controller2需要val frm pg1&pg2a.formPage1.jsp - > Controller1 - > formPage2b.jsp - > Controller3需要val frm pg1&pg2b.formPage1.jsp - > Controller1 - > formPage2c.jsp - > Controller4需要val frm pg1&pg2c.
如上所示,formPage1.jsp可以加载formPage2a,formPage2b或formPage2c.根据formPage1.jsp中提供的输入,它转到控制器(它是SimpleFormController的扩展),控制器获取user = command对象输入的值.
我希望能够在将formPage2a,formPage2b或formPage2c提交给另一个控制器时使用这些命令对象值.
这是当前的代码:
<form:form method="post" commandName="gainLossRequest">
<form:errors path="*" cssClass="error"/>
<table>
<tr>
<td>
<table>
<tr>
<td><h4>Choose Client</h4></td>
<td style="font-size: medium; font-family: Arial, bold; color: red">*</td>
</tr>
</table>
</td>
<td>
<form:select path="client">
<form:option value="none" label="Select" />
<form:option value="abc" label="abc" /> …Run Code Online (Sandbox Code Playgroud)