我是Spring的新手,我正在尝试使用以下堆栈创建一个webapp:Apache Tomcat 7,MySQL,Spring MVC,带有JPA注释的Hibernate 3.
我正试图通过遵循Craig Walls的"Spring in Action,第三版"一书来学习.
首先,我想创建一个页面,显示我手动添加到我的数据库中的一些条目,但看起来我的应用程序无法从SessionFactory创建/检索任何Hibernate会话.这是我的根本原因堆栈跟踪:
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:687)
com.nbarraille.www.dao.HibernateContactDAO.listContact(HibernateContactDAO.java:27)
com.nbarraille.www.controllers.HomeController.showHomePage(HomeController.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:613)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
Run Code Online (Sandbox Code Playgroud)
这是我关心的Classes/Config文件:
我的HibernateDAO:
@Repository
public …Run Code Online (Sandbox Code Playgroud) 我在Java中创建了一个简单的同步Stack对象,仅用于培训目的.这是我做的:
public class SynchronizedStack {
private ArrayDeque<Integer> stack;
public SynchronizedStack(){
this.stack = new ArrayDeque<Integer>();
}
public synchronized Integer pop(){
return this.stack.pop();
}
public synchronized int forcePop(){
while(isEmpty()){
System.out.println(" Stack is empty");
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return this.stack.pop();
}
public synchronized void push(int i){
this.stack.push(i);
notifyAll();
}
public boolean isEmpty(){
return this.stack.isEmpty();
}
public synchronized void pushAll(int[] d){
for(int i = 0; i < d.length; i++){
this.stack.push(i);
}
notifyAll();
}
public synchronized String toString(){ …Run Code Online (Sandbox Code Playgroud) 我在处理JNA中的回调时遇到问题.
我正在尝试使用一个使用回调来处理多个会话事件的C API(登录,注销,连接问题......).
会话对象(被调用sp_session)是一个不透明的结构.所有回调都在sp_session_callbacks结构中注册.根据API,我应该声明回调对象,并将其放入我将在创建sp_session对象时提供的Config对象中.如果我不想使用某些回调,我应该用它来初始化它们null.API正在使用__stdcall调用约定.
这是与我的问题相关的C标题的片段:
#define SP_CALLCONV __stdcall
typedef struct sp_session sp_session; ///< Representation of a session
typedef enum sp_error {
SP_ERROR_OK = 0,
SP_ERROR_BAD_API_VERSION = 1,
/* More errors */
} sp_error;
typedef struct sp_session_callbacks {
/**
* Called when login has been processed and was successful
*/
void (SP_CALLCONV *logged_in)(sp_session *session, sp_error error);
/**
* Called when logout has been processed. Either called explicitly
* if you initialize …Run Code Online (Sandbox Code Playgroud) 我是Django的新手并开始一个项目,我想以正确的方式做到这一点.
我想知道您认为组织项目的最佳做法.
以下是我的一些问题:
这是我当前的文件层次结构:
webapps/
myproject/
apache/
bin/
lib/
templates/
app1/
app2/
src/
app1/
app2/
__init.py
settings.py
urls.py
manage.py
myproject.wsgi
admin/
static/
css/
img/
Run Code Online (Sandbox Code Playgroud)
你怎么看?什么会更好?
谢谢!
我想知道是否可以从"全局"配置(URL,中间件类)中分离Django中的"本地"配置(本地路径到静态,模板内容必须是绝对的,本地数据库信息等等)... ,安装的应用程序等...),以便几个人可以通过Git或SVN在同一个项目上工作,而无需每次提交完成时都重写本地设置!
谢谢!
我提前道歉提出这个问题,我知道类似的问题已经被问了好几百次,但尽管我多次阅读Android屏幕支持指南,但我仍然不明白如何创建一个适合的基本布局几个屏幕无法使用比例尺寸.
所以基本上,如果我总结一下本指南告诉我们要做的事情:
RelativeLayout或FrameLayout代替AbsoluteLayoutdp尺寸而不是px尺寸来摆脱密度差异问题.好.这是有道理的.
现在,这是我的问题(我提前为他们的愚蠢道歉):
density groups如果我使用Density Independent Pixels (dp)尺寸,为什么必须为不同的创建不同的布局资源?dp尺寸来做到这一点?谢谢你,再次抱歉再次讨论这个话题......
我们正在使用Django开始一个Web项目(并且对此非常新),我想知道什么是设置高效开发环境的最佳方法.
这是一些信息:
到目前为止,我们没有设置任何本地开发服务器,我们正在通过Github同步对服务器的修改.但这不是很方便......
我们考虑在本地设置apache服务器,它使用远程数据库,并且只在一段时间内同步一次.
你认为会更好吗?
您有其他想法/其他提示吗?
谢谢!
我有一个在后台运行的线程程序,它为每个线程创建一个 QApplication(),并且每次我在我的 Dock 上有一个新的 Python Launcher 图标时。
有没有办法启动 QApplication() 而不在 OSX 上创建停靠图标?
谢谢!
我不能让Capybara在我的许多集成测试中工作.
当我访问某些页面时,我得到以下html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
Run Code Online (Sandbox Code Playgroud)
所以当我尝试使用have_content()选择器时,它会引发以下错误:
Failure/Error: page.should have_content("HELLO")
Capybara::ElementNotFound:
Unable to find xpath "/html"
Run Code Online (Sandbox Code Playgroud)
我可以访问的应用程序的某些页面很好,但其他一些我不能.甚至有些页面可以在某些地方使用,而不是在其他地方使用:
require 'spec_helper'
describe HomeController do
it "shows the website description" do
visit root_path
puts page.html.length # ==> 108 (no html)
...
end
end
require 'spec_helper'
describe FlowsController do
it "should do stuff" do
visit root_path
puts page.html.length # ==> 4459, works even if the exact same one didn't work in home_controller_spec!
visit flows_path
puts page.html.length # ==> …Run Code Online (Sandbox Code Playgroud)