只需要社区评估的东西.以下是一段代码,它是一个创建特定类型实例的简单工厂.该方法将在上下文中将bean注册为原型并返回实例.这是我第一次在运行时配置bean.你能评价并提供反馈意见吗?先感谢您.
package au.com.flexcontacts.flexoperations;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.AbstractApplicationContext;
import au.com.flexcontacts.exceptions.SyncClassCreactionError;
/**
* @author khushroo.mistry
* Class purpose: Simple Factory to create an
* instance of SynchroniseContactsService and register it in the Spring IoC.
*/
public final class FLEXSyncFactory implements ApplicationContextAware {
private static AbstractApplicationContext context;
/**
* @param username
* @param password
* @param syncType
* @return the correct service class
* @throws SyncClassCreactionError
* The method registers the …Run Code Online (Sandbox Code Playgroud) 想问一个关于spring-mvc控制器的最佳实践问题.请查看以下代码:
@Autowired
SomeService service;
@RequestMapping (...)
public @ResponseBody Response createSomething () {
try {
serviceResponse = service.doSomething();
//create a success response and return
}
catch (SomeServiceException e) {
//create an error response and return
}
}
Run Code Online (Sandbox Code Playgroud)
错误处理是否在控制器级别正常进行?或者服务类是否应该抛出如上所示的异常.请查看并告知我们.
我正在使用Spring In Action(第3版)一书学习Spring.我在书中遇到了一个不适合我的例子.以下是详细信息:
我试图使用Spring AOP在bean中引入新功能:
这是类结构:
执行者界面
public interface Performer {
void perform();
}
Run Code Online (Sandbox Code Playgroud)
班级乐器演奏家
package chapter4;
public class Instrmentalist implements Performer {
public void perform() {
System.out.println("Sining hey hey, hey");
}
}
Run Code Online (Sandbox Code Playgroud)
参赛者界面
package chapter4;
public interface Contestant {
void receiveAward();
}
Run Code Online (Sandbox Code Playgroud)
GraciousContestant Class
package chapter4;
public class GraciousContestant implements Contestant {
public void receiveAward() {
System.out.println("Won a car worth 4K!");
}
}
Run Code Online (Sandbox Code Playgroud)
我的Spring配置文件名为"spring-idol2.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:aop="http://www.springframework.org/schema/aop"
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.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context …Run Code Online (Sandbox Code Playgroud)