@Entity @Table(name = "jforum_categories") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Component @PrototypeScoped public class Category implements Serializable { @Id @SequenceGenerator(name = "sequence", sequenceName = "jforum_categories_seq") @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequence") @Column(name = "category_id") private int id; @Column(name = "category_order") private int displayOrder; @Column(name = "category_moderated") private boolean moderated; @Column(name = "category_title") private String name; @Transient private CategoryRepository repository; public Category() {} @Autowired public Category(CategoryRepository repository) { this.repository = repository; } public List<Forum> getForums() { return this.repository.getForums(this); } …… }
public class SpringInterceptor extends EmptyInterceptor { private final SessionFactory sessionFactory; private final ApplicationContext beanRegistry; public SpringInterceptor(ApplicationContext beanRegistry, SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; this.beanRegistry = beanRegistry; } @Override public Object instantiate(String entityName, EntityMode entityMode, Serializable id) { if (!EntityMode.POJO.equals(entityMode)) { return null; } Class<?> c = getClassByName(entityName); Object instance = this.beanRegistry.getBean(c); sessionFactory.getClassMetadata(c).setIdentifier(instance, id, EntityMode.POJO); return instance; } private Class<?> getClassByName(String name) { try { return Class.forName(name); } catch (ClassNotFoundException e) { throw new ForumException(e); } } }
2、具體問題 java
1.好好看一下Vraptor3.5的文檔(http://vraptor.caelum.com.br/en/docs/one-minute-guide/)會節約你不少時間,文檔精簡的很,沒多少。 spring
2.包的問題,用Vraptor3.5裏的包,大部分都有了。 數據庫
3.從Hibernate3.2升級後,有一些小問題要改,最多的是uniqueResult()的結果是Long型,不能再轉Integer了。 session
4.JForumTag裏須要本身從springContext裏拿Bean: 架構
springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.pageContext().getServletContext());
5.頁面有些小問題,改改連接就行了,zh_CN.properties裏有些字段沒有,補齊便可。 框架
6.上傳文件大小的問題,Vraptor3.5默認上傳文件的大小是兩兆,須要從新配置(用代碼): jsp
@Component @ApplicationScoped public class CustomMultipartConfig extends DefaultMultipartConfig{ public long getSizeLimit() { return 50 * 1024 * 1024; // 50MB } }