我正在读"用于Web应用程序的专业Java - Nicholas S. Williams"这本书的例子有Spring Data JPA的这个配置:
@Bean
public DataSource customerSupportDataSource()
{
JndiDataSourceLookup lookup = new JndiDataSourceLookup();
return lookup.getDataSource("jdbc/CustomerSupport");
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean()
{
Map<String, Object> properties = new Hashtable<>();
properties.put("javax.persistence.schema-generation.database.action",
"none");
properties.put("hibernate.ejb.use_class_enhancer", "true");
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect");
LocalContainerEntityManagerFactoryBean factory =
new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(adapter);
factory.setDataSource(this.customerSupportDataSource());
factory.setPackagesToScan("com.wrox.site.entities",
"com.wrox.site.converters");
factory.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
factory.setValidationMode(ValidationMode.NONE);
factory.setLoadTimeWeaver(this.loadTimeWeaver); // TODO: remove when SPR-10856 fixed
factory.setJpaPropertyMap(properties);
return factory;
}
@Bean
public PlatformTransactionManager jpaTransactionManager()
{
return new JpaTransactionManager(
this.entityManagerFactoryBean().getObject()
);
}
Run Code Online (Sandbox Code Playgroud)
但我一直在使用XML进行配置,我无法弄清楚如何将其转换为XML,到目前为止我已经知道了
<jee:jndi-lookup id="myDataSource" jndi-name="java:comp/env/jdbc/test"/>
<bean id="transactionManager" …Run Code Online (Sandbox Code Playgroud) 我刚刚基于此制作了我的第一个REST api http://www.vogella.com/articles/REST/article.html. 我使用的是eclipse kepler,tomcat7和Jersey
当我尝试"在服务器上运行"时,我收到此错误:
SEVERE: Servlet /de.vogella.jersey.first threw load() exception
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
这是源代码:
package de.vogella.jersey.first;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class Hello {
// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() …Run Code Online (Sandbox Code Playgroud) 我有测试Spring Data JPA的示例测试程序,但似乎没有生成存储库.
我的配置:
<?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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd">
<import resource="securityConfig.xml" />
<context:annotation-config />
<context:component-scan base-package="com.test">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<jee:jndi-lookup id="myDataSource" jndi-name="java:comp/env/jdbc/test"/>
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan" value="com.test.security" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="myEmf" />
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
用户实体:
package com.test.security;
import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.userdetails.UserDetails;
@Entity
@Table
public class …Run Code Online (Sandbox Code Playgroud) 假设有一个包含3列A,B和C的表.A是主键.我有两种类型的查询,一种是按A和B搜索,另一种是按A和C搜索.最好是根据A和C为C搜索添加二级索引,或者用A,C创建一个新表,和B列.
为了把它放在不同的角度来看,在总体上是一个坏主意,有两列中的两个二级指标,并有两个索引where子句条件.结合主键和二级索引是否相同?
我是cassandra和moven的新手.我试图在eclipse中编写一个简单的java程序,它使用cassandra java驱动程序连接到我设置的cassandra节点.我找到了这个存储库https://github.com/datastax/java-driver但我不知道我应该怎么做.任何人都可以给我一步一步的说明来获取驱动程序并创建一个使用驱动程序的简单eclipse项目.