spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
923 stars 562 forks source link

Not getting the CRUD operations #63

Open bytor99999 opened 11 years ago

bytor99999 commented 11 years ago

I have a simple JpaRepository, but when I do discover in the rest shell it doesn't show any CRUD operations.

Here is my code for the repo

public interface CurrencyRepository extends JpaRepository<Currency, Long> { }

This is a current Spring MVC app, so we just included

I see there is mapping being done in the tomcat log, but no CRUD operations show in discover.

jbrisbin commented 11 years ago

You have to extend CrudRepository or PagingAndSortingRepository.

Sent from my iPhone

On Jan 25, 2013, at 7:30 PM, Mark Spritzler notifications@github.com wrote:

I have a simple JpaRepository, but when I do discover in the rest shell it doesn't show any CRUD operations.

Here is my code for the repo

public interface CurrencyRepository extends JpaRepository { }

This is a current Spring MVC app, so we just included

I see there is mapping being done in the tomcat log, but no CRUD operations show in discover.

— Reply to this email directly or view it on GitHub.

bytor99999 commented 11 years ago

I thought JpaRepository already extends CrudRepository?

Thanks Jon

Mark

On Jan 26, 2013, at 8:25 AM, Jon Brisbin notifications@github.com wrote:

You have to extend CrudRepository or PagingAndSortingRepository.

Sent from my iPhone

On Jan 25, 2013, at 7:30 PM, Mark Spritzler notifications@github.com wrote:

I have a simple JpaRepository, but when I do discover in the rest shell it doesn't show any CRUD operations.

Here is my code for the repo

public interface CurrencyRepository extends JpaRepository { }

This is a current Spring MVC app, so we just included

I see there is mapping being done in the tomcat log, but no CRUD operations show in discover.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

jbrisbin commented 11 years ago

It could be that it's not searching superinterfaces. The latest code in master does things completely differently w.r.t. metadata so shouldn't have that problem. Do you have others that are direct subclasses of CrudRepository and do show up?

On Jan 26, 2013, at 12:26 PM, Mark Spritzler notifications@github.com wrote:

I thought JpaRepository already extends CrudRepository?

Thanks Jon

Mark

On Jan 26, 2013, at 8:25 AM, Jon Brisbin notifications@github.com wrote:

You have to extend CrudRepository or PagingAndSortingRepository.

Sent from my iPhone

On Jan 25, 2013, at 7:30 PM, Mark Spritzler notifications@github.com wrote:

I have a simple JpaRepository, but when I do discover in the rest shell it doesn't show any CRUD operations.

Here is my code for the repo

public interface CurrencyRepository extends JpaRepository { }

This is a current Spring MVC app, so we just included

I see there is mapping being done in the tomcat log, but no CRUD operations show in discover.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

bytor99999 commented 11 years ago

No. I can try that out. Make it extend Crud and Jpa Repository.

Is master, um almost, closely production ready???

Thanks

Mark

On Sat, Jan 26, 2013 at 10:55 AM, Jon Brisbin notifications@github.comwrote:

It could be that it's not searching superinterfaces. The latest code in master does things completely differently w.r.t. metadata so shouldn't have that problem. Do you have others that are direct subclasses of CrudRepository and do show up?

On Jan 26, 2013, at 12:26 PM, Mark Spritzler notifications@github.com wrote:

I thought JpaRepository already extends CrudRepository?

Thanks Jon

Mark

On Jan 26, 2013, at 8:25 AM, Jon Brisbin notifications@github.com wrote:

You have to extend CrudRepository or PagingAndSortingRepository.

Sent from my iPhone

On Jan 25, 2013, at 7:30 PM, Mark Spritzler notifications@github.com wrote:

I have a simple JpaRepository, but when I do discover in the rest shell it doesn't show any CRUD operations.

Here is my code for the repo

public interface CurrencyRepository extends JpaRepository { }

This is a current Spring MVC app, so we just included

I see there is mapping being done in the tomcat log, but no CRUD operations show in discover.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHubhttps://github.com/SpringSource/spring-data-rest/issues/63#issuecomment-12740085.

jbrisbin commented 11 years ago

On Jan 26, 2013, at 1:38 PM, Mark Spritzler notifications@github.com wrote:

Is master, um almost, closely production ready???

Not yet. Working on a comprehensive test suite now. A week or two probably.

bytor99999 commented 11 years ago

I just made my repositories extend JpaRepository and CrudRepository. Tried to make it just extend CrudRepository and it still isn't exporting CRUD save etc. Just search.

Thanks

Mark

On Sat, Jan 26, 2013 at 11:41 AM, Jon Brisbin notifications@github.comwrote:

On Jan 26, 2013, at 1:38 PM, Mark Spritzler notifications@github.com wrote:

Is master, um almost, closely production ready???

Not yet. Working on a comprehensive test suite now. A week or two probably.

— Reply to this email directly or view it on GitHubhttps://github.com/SpringSource/spring-data-rest/issues/63#issuecomment-12740903.

jbrisbin commented 11 years ago

Can you send me some example code of what your setup is like (including domain model and Repository)? There's something weird going on and it's not apparent to me so far why this should be any different than the test situation I'm working on today which seems to work fine.

On Jan 28, 2013, at 11:56 AM, Mark Spritzler notifications@github.com wrote:

I just made my repositories extend JpaRepository and CrudRepository. Tried to make it just extend CrudRepository and it still isn't exporting CRUD save etc. Just search.

Thanks

Mark

On Sat, Jan 26, 2013 at 11:41 AM, Jon Brisbin notifications@github.comwrote:

On Jan 26, 2013, at 1:38 PM, Mark Spritzler notifications@github.com wrote:

Is master, um almost, closely production ready???

Not yet. Working on a comprehensive test suite now. A week or two probably.

— Reply to this email directly or view it on GitHubhttps://github.com/SpringSource/spring-data-rest/issues/63#issuecomment-12740903.

— Reply to this email directly or view it on GitHub.

bytor99999 commented 11 years ago

So I am using the style of adding Spring Data Rest to an already existing Spring MVC app. So there isn't a special Spring Rest Servlet deployed in web.xml.

It also brings up a bizarre problem. I am also using Spring Security and didn't want to have to put a url-intercept tag for each and every repository exported by Spring Rest. I would rather them have /someUrl/{repository} where someUrl is different than the ServletMapping for the DispatcherServlet?

OK, let me get you some sample of what I can.

Thanks

Mark

On Mon, Jan 28, 2013 at 9:55 AM, Mark Spritzler bytor99999@gmail.comwrote:

I just made my repositories extend JpaRepository and CrudRepository. Tried to make it just extend CrudRepository and it still isn't exporting CRUD save etc. Just search.

Thanks

Mark

On Sat, Jan 26, 2013 at 11:41 AM, Jon Brisbin notifications@github.comwrote:

On Jan 26, 2013, at 1:38 PM, Mark Spritzler notifications@github.com wrote:

Is master, um almost, closely production ready???

Not yet. Working on a comprehensive test suite now. A week or two probably.

— Reply to this email directly or view it on GitHubhttps://github.com/SpringSource/spring-data-rest/issues/63#issuecomment-12740903.

bytor99999 commented 11 years ago

After pasting all this, there isn't anything in there that I see that is out of the ordinary. I mean except for my specific classes all the configs would be in almost 90+ % of projects out there. Thanks for taking the time to look at this.

Mark

The web.xml is very standard. ContextLoaderListener with WEB-INF/applicationContext default naming. DispatcherServlet with WEB-INF/servletName-servlet.xml default naming. Spring Security DelegatingFilterProxy.

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>hdpoker</display-name>

<!-- Enable escaping of form submission contents -->

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
org.springframework.web.filter.DelegatingFilterProxy
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>CharacterEncodingFilter</filter-name>
org.springframework.web.filter.CharacterEncodingFilter
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Bootstrap the root application context as usual using

ContextLoaderListener -->

org.springframework.web.context.ContextLoaderListener
<!-- Handles Spring requests -->
<servlet>
    <servlet-name>hdpoker</servlet-name>
org.springframework.web.servlet.DispatcherServlet
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>hdpoker</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<session-config>
    <session-timeout>0</session-timeout>
</session-config>

<mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
</mime-mapping>

Here is my config for 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:util="http://www.springframework.org/schema/util" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx=" http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util

http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/data/jpa

http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

<util:properties id="postgresProperties"

location="classpath:META-INF/spring/postgres.properties"/>

<bean

class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

<bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource">
    <property name="portNumber"

value="#{postgresProperties['postgres.port']}"/> <property name="user" value="#{postgresProperties['postgres.username']}"/> <property name="serverName" value="#{postgresProperties['postgres.url']}"/> <property name="databaseName" value="#{postgresProperties['postgres.databasename']}"/>

<bean id="entityManagerFactory"

class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

    <property name="jpaVendorAdapter" ref="jpaAdapter"/>
    <property name="loadTimeWeaver">
        <bean

class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>

    <property name="packagesToScan">
        <list>
            <value>com.hdpoker.account</value>
        </list>
    </property>
</bean>
<bean id="transactionManager"

class="org.springframework.orm.jpa.JpaTransactionManager">

</bean>
<bean id="jpaAdapter"

class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

    <property name="showSql" value="true"/>
    <property name="generateDdl" value="true"/>
</bean>
<jpa:repositories base-package="com.hdpoker.account.repository.jpa"

entity-manager-factory-ref="entityManagerFactory"/> tx:annotation-driven/

Here is the hdpoker-servlet.xml file (Most of it is copied/pasted from a ROO project a year ago, except the top line for Spring Data Rest)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<!-- Bean for Spring Data REST to export Spring Data JPA Repositories

to a HATEOS REST Api--> <bean class="org.springframework.data.rest.webmvc.RepositoryRestMvcConfiguration"/>

<context:component-scan base-package="com.hdpoker.controller" use-default-filters="false"> <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/> /context:component-scan

mvc:annotation-driven/

<mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/>

mvc:default-servlet-handler/

mvc:interceptors

/mvc:interceptors

<mvc:view-controller path="/" view-name="index"/>
<bean id="viewResolver"

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

    <property name="suffix" value=".jsp"/>
</bean>

<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource"> <property name="basenames" value="WEB-INF/i18n/messages,WEB-INF/i18n/application"/>

</bean>

<bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" id="localeResolver">

<bean class="org.springframework.ui.context.support.ResourceBundleThemeSource" id="themeSource"/>

<bean class="org.springframework.web.servlet.theme.CookieThemeResolver" id="themeResolver">

<bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver"/>

Standard xml for JPA. LocalContainerEntityManagerFactory, Datasource pointing to Postgres, JpaTransactionManager, <jpa:repositories base-package="com.hdpoker.account.repository.jpa" entity-manager-factory-ref="entityManagerFactory"/>

Repo:

public interface AccountSecurityRepository extends JpaRepository<AccountSecurity, Long>, CrudRepository<AccountSecurity, Long> { AccountSecurity findByUsername(String username); }

Domain object: This is a Groovy class.

@Entity @Table(name="AccountUser") class AccountSecurity implements UserDetails {

@Id @GeneratedValue(strategy = GenerationType.AUTO) Long id;

Long nodeId; @Transient Account account;

String firstName; String lastName; Locale locale; TimeZone timeZone; Date lastModified; Date birthday;

@ManyToOne @JoinColumn(name="currency_id") com.hdpoker.account.account.Currency currencyId;

String email;

@ManyToMany(cascade = CascadeType.ALL) Set groups;

@ManyToMany(cascade = CascadeType.ALL) Set roles;

public Collection<? extends GrantedAuthority> getAuthorities() { final Collection authorities = new ArrayList(); for (UserRole role : roles) { authorities.add(new SimpleGrantedAuthority(role.getRole())); }

for (UserGroup group : groups) {
  authorities.add(new SimpleGrantedAuthority(group.getName()));
}
return authorities;

}

String password;

@NotNull String username;

@Transient boolean accountNonExpired = true;

@Transient boolean accountNonLocked = true;

@Transient boolean credentialsNonExpired = true;

@Transient boolean enabled = true;

private void setId(Long id){} }

On Mon, Jan 28, 2013 at 10:03 AM, Jon Brisbin notifications@github.comwrote:

Can you send me some example code of what your setup is like (including domain model and Repository)? There's something weird going on and it's not apparent to me so far why this should be any different than the test situation I'm working on today which seems to work fine.

On Jan 28, 2013, at 11:56 AM, Mark Spritzler notifications@github.com wrote:

I just made my repositories extend JpaRepository and CrudRepository. Tried to make it just extend CrudRepository and it still isn't exporting CRUD save etc. Just search.

Thanks

Mark

On Sat, Jan 26, 2013 at 11:41 AM, Jon Brisbin notifications@github.comwrote:

On Jan 26, 2013, at 1:38 PM, Mark Spritzler notifications@github.com

wrote:

Is master, um almost, closely production ready???

Not yet. Working on a comprehensive test suite now. A week or two probably.

— Reply to this email directly or view it on GitHub< https://github.com/SpringSource/spring-data-rest/issues/63#issuecomment-12740903>.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHubhttps://github.com/SpringSource/spring-data-rest/issues/63#issuecomment-12794879.