我在编写API和核心功能时编写单元测试.但是我想成为一个吃着睡觉,呼吸TDD和BDD的酷迷.以正确的方式开始使用TDD/BDD的最佳方法是什么?任何书籍,资源,框架,最佳实践?
我的环境是带有Grails前端的Java后端,与几个外部Web服务和数据库集成在一起.
有谁知道我是否应该使用属性占位符作为限定符中的表达式?我似乎无法让这个工作.
我使用的是Spring 3.0.4.
@Controller
public class MyController {
@Autowired
@Qualifier("${service.class}")
Service service;
}
@Service
@Qualifier("ServiceA")
ServiceA implements Service {
public void print() {
System.out.println("printing ServiceA.print()");
}
}
@Service
@Qualifier("ServiceB")
ServiceB implements Service {
public void print() {
System.out.println("printing ServiceB.print()");
}
}
Run Code Online (Sandbox Code Playgroud)
XML:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:/etc/config.properties"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
config.properties:
config.properties
service.class=serviceB
Run Code Online (Sandbox Code Playgroud) 我认识了很多敏捷人员工作得很好的人,他们中的大多数往往是计划和委派工作的经理和建筑师.但是我真的没有发现很多优秀的开发人员确信敏捷正在为他们工作.
当然你可以说敏捷不适合你,你做得不对.但是,除了敏捷的任何混音之外,它是否适合作为开发人员?为什么?有没有人认为,在传统(或接近)的团队结构中,敏捷感觉更像是一种微观管理而非自我管理?
我有一个类似以下的Java线程:
public class MyThread extends Thread {
MyService service;
String id;
public MyThread(String id) {
this.id = node;
}
public void run() {
User user = service.getUser(id)
}
}
Run Code Online (Sandbox Code Playgroud)
我有大约300个ID,每隔几秒钟 - 我启动线程来为每个id打个电话.例如.
for(String id: ids) {
MyThread thread = new MyThread(id);
thread.start();
}
Run Code Online (Sandbox Code Playgroud)
现在,我想从每个线程收集结果,并对数据库进行批量插入,而不是每2秒进行300次数据库插入.
知道我怎么能做到这一点?
除了以编程方式测量存储在会话中的每种数据类型(每个对象组成)的大小之外,是否有一种简洁的方法来测量它?
我的Web应用程序运行时带有后端服务的默认impl.一个人应该能够实现接口并将jar放入plugins文件夹(不在apps类路径中).重新启动服务器后,我们的想法是将新jar加载到类加载器中,并让它参与依赖注入.我使用@Autowired使用Spring DI.新的插件服务impl将具有@Primary注释.因此,给定两个接口的impls,应该加载primary.
我将jar加载到类加载器中并可以手动调用impl.但是我无法参与依赖注入,并让它替换默认的impl.
这是一个简化的例子:
@Controller
public class MyController {
@Autowired
Service service;
}
//default.jar
@Service
DefaultService implements Service {
public void print() {
System.out.println("printing DefaultService.print()");
}
}
//plugin.jar not in classpath yet
@Service
@Primary
MyNewService implements Service {
public void print() {
System.out.println("printing MyNewService.print()");
}
}
Run Code Online (Sandbox Code Playgroud)
//由于缺少更好的地方,我从ContextListener加载了插件jar
public class PluginContextLoaderListener extends org.springframework.web.context.ContextLoaderListener {
@Override
protected void customizeContext(ServletContext servletContext,
ConfigurableWebApplicationContext wac) {
System.out.println("Init Plugin");
PluginManager pluginManager = PluginManagerFactory.createPluginManager("plugins");
pluginManager.init();
//Prints the MyNewService.print() method
Service service = (Service) pluginManager.getService("service");
service.print();
}
} …
Run Code Online (Sandbox Code Playgroud) 用户配置文件图像存储在单独的文件服务器中,我正在考虑在memcached中缓存它们.memcached服务器是应用程序的本地服务器,每个映像小于1MB.
但我在这里看到使用memcached图像是一个坏主意.是真的吗?我真的不相信.
有什么最佳做法和建议吗?我正在使用SpyMemcached Java Client.
资源/ user/12345不存在.让我们说消费者正在随机尝试不同的ID.没有授权.任何用户都可以查看任何用户.从更广泛的意义上讲,我的问题是"如果您对不存在的资源进行GET,您应该返回什么?"
我应该为一个不存在的id返回一个空用户,还是应该返回一个包含正确状态代码的错误消息?
什么是典型/通常/推荐的做法?
在grails中创建URL的标准方法是:
<a href="${createLink(controller:'news', action: 'show', params: [id: news.id])}">${news.title}</a>
Run Code Online (Sandbox Code Playgroud)
生成网址: /news/show/102
我想要更多SEO友好的URL,如:
/news/102/this-is-the-hottest-news-today
Run Code Online (Sandbox Code Playgroud)
在Grails中最干净的方法是什么?我可以使用grails URLMapping映射/news/show/102
到/news/102
,但我如何创建像上面这样的完整URL?
我有一个弹簧注入Dao的单例(简化如下):
public class MyService<T> implements Service<T> {
private final Map<String, T> objects;
private static MyService instance;
MyDao myDao;
public void set MyDao(MyDao myDao) {
this. myDao = myDao;
}
private MyService() {
this.objects = Collections.synchronizedMap(new HashMap<String, T>());
// start a background thread that runs for ever
}
public static synchronized MyService getInstance() {
if(instance == null) {
instance = new MyService();
}
return instance;
}
public void doSomething() {
myDao.persist(objects);
}
}
Run Code Online (Sandbox Code Playgroud)
我的spring配置可能如下所示:
<bean id="service" class="MyService" factory-method="getInstance"/>
Run Code Online (Sandbox Code Playgroud)
但这将在启动期间实例化MyService.
是否有一种编程方式将MyDao依赖注入MyService,但没有spring管理MyService?
基本上我希望能够从我的代码中执行此操作: …
java ×5
spring ×3
grails ×2
agile ×1
bdd ×1
caching ×1
concurrency ×1
httpsession ×1
java-ee ×1
memcached ×1
methodology ×1
plugins ×1
rest ×1
seo ×1
singleton ×1
tdd ×1
tomcat ×1
unit-testing ×1
url ×1
url-mapping ×1