java和scala代码 scala和java混编( 三 )


goals
goaltestCompile/goal
/goals
/execution
/executions
/plugin
/plugins
finalNamemyapp/finalName
/build
/project
web xml中设置
接下来 修改main/webapp/WEB INF/web xml 从而确立了Wicket的过滤器 打开Spring的JPA实体管理器和Spring监听器 进行Spring的初始化
?xml version= encoding= UTF ?
web app version= xmlns= xmlns:xsi= instance
xsi:schemaLocation= app_ _ xsd
filter
filter namef /filter name
filter class springframework orm jpa support OpenEntityManagerInViewFilter/filter class
/filter
filter
filter namef /filter name
filter class apache wicket protocol WicketFilter/filter class
init param
param nameapplicationClassName/param name
param value foo myapp MyApp/param value
/init param
/filter
filter mapping
filter namef /filter name
url pattern/app/*/url pattern
/filter mapping
filter mapping
filter namef /filter name
url pattern/*/url pattern
/filter mapping
context param
param namecontextConfigLocation/param name
param valueclasspath:/beans xml/param value
/context param
listener
listener class sprntext ContextLoaderListener/listener class
/listener
/web app
设置Spring bean访问和调用的数据库
要定义这些Spring bean 创建main/resources的beans xml以及一下的内容
?xml version= encoding= UTF ?
beansxmln *** eansxmlns=
xmlns:xsi= instance
xmlns:context=
xmlns:tx=
xsi:schemaLocation=
beans xsd
context xsd
tx xsd
context:ponent scan base package= foo myapp /
bean id= emf class= springframework orm jpa LocalContainerEntityManagerFactoryBean
property name= persistenceXmlLocation value= https://www.04ip.com/post/classpath:/META INF/my persistence xml /
/bean
bean id= transactionManager class= springframework orm jpa JpaTransactionManager
property name= entityManagerFactory ref= emf /
/bean
tx:annotation driven /
/beans
读取数据库配置中persistence xml文件 在这里 您将获得一个主目录中名为MyApp的H 数据库 因此 创建main/resources/META INF文件的内容如下
persistencexmlnspersistencexmlns=
xmlns:xsi= instance
xsi:schemaLocation= _ _ xsd
version=
persistence unit name= myapp transaction type= RESOURCE_LOCAL
provider hibernate ejb HibernatePersistence/provider
properties
propertynamepropertyname= nnection driver_class value= https://www.04ip.com/post/h Driver /
property name= nnection url value= https://www.04ip.com/post/jdbc:h :tcp://localhost/~/myapp /
propertynamepropertyname= nnection username value= https://www.04ip.com/post/sa /
propertynamepropertyname= nnection password value= https://www.04ip.com/
property name= hibernate dialect value= https://www.04ip.com/post/hibernate dialect H Dialect /
property name= hibernate hbm ddl auto value= https://www.04ip.com/post/create /
/properties
/persistence unit
/persistence
创建Wicket的页面
在这里 您将创建一个Wicket页面显示从数据库加载一些内容 因此 创建主/Scala文件夹 右键单击它并选择新建|Scala类 命名为我的页面类和投入 foo myapp包中 如下所示
package foo myapp
import apacl _
import basic Label
import list {ListItem ListView}
import apache wicket spring injection annot SpringBean
import apache wicket model CompoundPropertyModel
class MyPage extends WebPage {
@SpringBean
var ps: ProductService = _
val productListView = newListView[Product]( productListView ps getAll) {
def populateItem(item: ListItem[Product]) = {
item setModel(newCompoundPropertyModel[Product](item getDefaultModelObject))
item add(new Label( name ))

推荐阅读