I'm building a REST Webservice using Spring Boot (v 1.4.2.RELEASE). I'm trying to follow separation of concerns pattern, so I've created 3 maven projects,
myapp-repository, myapp-service and myapp-rest. myapp-service has a dependency of myapp-repository and myapp-rest has a dependency of myapp-service. Below is the initial configuration I've made.
myapp-repository
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
Repository Config
#Configuration
#EnableJpaRepositories
#ComponentScan("com.mycompany.myapp.repository")
#EntityScan("com.mycompany.myapp.entity")
#PropertySource("classpath:repository.properties")
public class RepositoryConfig {
#Bean
#Primary
#ConfigurationProperties(prefix = "myapp.primary.datasource")
public DataSource getDataSource() {
return DataSourceBuilder.create().build();
}
}
myapp-service
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.mycompany.myapp</groupId>
<artifactId>myapp-repository</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Service config
#Configuration
#ComponentScan("com.mycompany.myapp.service")
#Import(RepositoryConfig.class)
#PropertySource("classpath:service.properties")
public class ServiceConfig {
}
myapp-rest
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mycompany.myapp</groupId>
<artifactId>myapp-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Rest config
#SpringBootApplication
#ComponentScan("com.mycompany.myapp.rest")
#Import(ServiceConfig.class)
public class RestConfig extends SpringBootServletInitializer {
/**
* #param args
*/
public static void main(String[] args) {
SpringApplication.run(RestConfig.class, args);
}
}
Now, I want to restrict my repository services to be autowired in myapp-rest, but with this current implementation, it's possible. Only services inside myapp-service module should be allowed to autowire in myapp-rest. Is it possible?
Related
My application use spring boot and webflux with tomcat embedded.
I use a 3rd library that contains some servlet listeners.
A listener property injector of BagServletContextListener returns null when the app is started.
#WebListener
public class BagServletContextListener implements ServletContextListener {
#Autowired
private BagInjector injector;
#Override
public void contextInitialized(ServletContextEvent event) {
this.injector.inject();
}
}
How can I force initialization of this component through #bean or other way?
a piece of my pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Note: The packaging of app is a war.
The lack of initialization of this component cause null pointer exception in contextInitialized method.
[ERROR ] SRVE0283E: Exception caught while initializing context: java.lang.NullPointerException at com.devIo.ee.BagServletContextListener.contextInitialized(BagServletContextListener.java:33) at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2391) at [internal classes]
You have not told Spring Boot to scan your BagServletContextListener class. The #WebListener does not accomplish that.
Add #ServletComponentScan to your SpringBootApplication class to ensure the BagInjector is scanned - and Spring knows how to autowire it for you.
Like this:
#ServletComponentScan
#SpringBootApplication
public class SpringBootApp {
public static void main(String[] args) {
SpringApplication.run(SpringBootApp.class, args);
}
}
I have a working AOP (when using inside the project it is written in) but when I build this project (maven install), and use that JAR in another project, and try to use the #TimedLog annotation, nothing happens. I try to breakpoint into it, but it doesn't reach there.
It looks like this:
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.METHOD)
public #interface TimedLog {
boolean shouldAttachMethodArgs() default false;
boolean shouldAttachReturnValue() default false;
String message() default "";
}
This is the actual Aspect:
#Aspect
#Configuration
#Slf4j
public class MethodExecutionAspect {
#Pointcut("#annotation(timedLogVar)")
public void annotationPointCutDefinition(TimedLog timedLogVar) {}
#Pointcut("execution(* *(..))")
public void atExecution() {}
#Around(value = "annotationPointCutDefinition(timedLogVar) && atExecution()", argNames = "joinPoint,timedLogVar")
public Object around(ProceedingJoinPoint joinPoint, TimedLog timedLogVar) throws Throwable {
Stopwatch stopwatch = Stopwatch.createStarted();
Object returnValue = joinPoint.proceed();
stopwatch.stop();
log.info(String.format("test message %s", stopwatch.elapsed(TimeUnit.MILLISECONDS)));
return returnValue;
}
}
An implementation of it would be:
#TimedLog
void testDefaultValues() throws InterruptedException {
int sleepTimeInMillis = 200;
log.info("Resting for {} millis", value("sleepTimeInMillis", sleepTimeInMillis));
Thread.sleep(sleepTimeInMillis);
}
pom.xml
<!-- AOP -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.0.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
<scope>compile</scope>
</dependency>
From what you can see here, this is an AOP that decorates a method and logs its runtime.
I've been struggling with it for a while now, and would really appreciate your help.
Thanks
EDIT:
As requested, the full pom.xml of the project that's supposed to use that AOP (it lives foo.bar.utils:utils-common)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>backend</artifactId>
<groupId>foo.bar.backend</groupId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>backend-logic</artifactId>
<repositories>
<repository>
<id>maven-s3-release-repo</id>
<name>S3 Release Repository</name>
<url>s3://repository.foobar.com/releases</url>
</repository>
<repository>
<id>maven-s3-snapshot-repo</id>
<name>S3 Snapshot Repository</name>
<url>s3://repository.foobar.com/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>foo.bar.backend</groupId>
<artifactId>backend-contract</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<!-- Spring boot actuator to expose metrics endpoint -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Micormeter core dependecy -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<!-- Micrometer Prometheus registry -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- Common -->
<dependency>
<groupId>foo.bar.utils</groupId>
<artifactId>utils-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- Auth -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
<version>2.0.0.M1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>org.springframework.build</groupId>
<artifactId>aws-maven</artifactId>
<version>5.0.0.RELEASE</version>
</extension>
</extensions>
</build>
</project>
EDIT2:
The implementation that doesn't work (in the different project that's supposed to use the AOP)
#Slf4j
#Configuration
#EnableAspectJAutoProxy
public class TestingSomething {
#TimedLog(message = "test something")
public void testingSomething() {
log.info("ololol");
}
}
And the test, testing it:
#RunWith(SpringRunner.class)
#SpringBootTest(classes = SomeSpringConfiguration.class,
properties = {"server.port=0", "enable.security=true"})
#WebAppConfiguration
public class testingSomethingTest {
#Autowired
TestingSomething testingSomething;
#Test
public void testingLol() {
testingSomething.testingSomething();
}
}
For the aspects to work you need to enable them. To enable you need to either configure them through xml or through annotation:
#Configuration
#EnableAspectJAutoProxy
Through xml:
<beans …>
<!– Enable AspectJ auto-wiring –>
<aop:aspectj-autoproxy />
</beans>
When you include your jar into another application, this other application has its own configuration and context. Even if you have enabled the aspect autowiring for your original context you still need to do the same for your new application by one of the two ways pointed above.
If you use the annotation make sure it is within the component scan scope and that it is actualy included into your context.
UPDATE:
do #Import (MethodExecutionAspect.class) on your testingSomethingTest to ensure it is component scanned.
http://www.baeldung.com/spring-boot-custom-starter
I have followed tutorial and github example provided from the link above and have implemented similar way. I am using spring-boot-starter-parent :2.0.0.M3. Even after including my custom starter dependency in the pom for the app, it doesn't find required bean without #componentScan while deploying it.
It is giving following error.
APPLICATION FAILED TO START
Description:
Field fooApiCaller in com.core.controller.TestController required a bean of type 'service.ApiCaller' that could not be found.
Action:
Consider defining a bean of type 'service.ApiCaller' in your configuration.
Sample App ( one throwing error)
pom.xml
<dependency>
<groupId>abc.def</groupId>
<artifactId>custom-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
#Controller
public class FooController {
#Autowired
ApiCaller fooApiCaller
}
custom-starter module pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>abc.def</groupId>
<artifactId>custom-spring-boot-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>abc.def</groupId>
<artifactId>myapi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Autoconfiguration module dependency
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>abc.def</groupId>
<artifactId>myapi</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
spring factories code
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
abc.def.myapi.autoconfigure.AutoConfiguration
MyAPI product
#Service
#Configuration
public class ApiCaller {
public String getName(String Id){return "name";}
}
I have implemented a REST API using Spring Boot (version 1.3.6.RELEASE), which is working as expected. However I would like to add JSON API support to my application.
The problem is that I get a 404 when trying to execute a GET on a Katharsis resource.
The dependencies in pom.xml look as follows (I use Spring Security too):
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
</dependency>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dumbster</groupId>
<artifactId>dumbster</artifactId>
<version>1.6</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.katharsis</groupId>
<artifactId>katharsis-spring</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9</version>
</dependency>
</dependencies>
My application initialisation class is as follows:
#SpringBootApplication
#Configuration
#EnableAutoConfiguration(exclude = WebMvcAutoConfiguration.class)
#EnableSwagger2
#ComponentScan(basePackages = "com.myapp")
#Import({KatharsisConfigV2.class})
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
The resource class:
#ApiModel(description = "")
#JsonApiResource(type = "foo-data")
public class FooData extends DomainRepresentation {
#JsonApiId
private String id = null;
#JsonProperty
private String name = null;
// .... getters & setters
}
ResourceRepository class:
#JsonApiResourceRepository(FooData.class)
#Component
public class FooDataKatApi extends MyApi {
#Autowired
private FooDataService fooDataService;
#JsonApiFindOne
public FooData foodataIdGet(String id, QueryParams requestParams) {
FooData result = fooDataService.getFooDataById(id);
return result;
}
}
If I add Spring #ResourceMappings than I get data back but without Katharsis additions like "link", etc. It's as if the API call is not being picked up by Katharsis, but it's handled by Spring.
Any help would be appreciated.
-- EDITTED --
The FooDataService is as follows:
#Service
public class FooDataService extends MyService {
#Autowired
private FooDataRepository fooDataRepository;
public FooData getFooDataById(String id) {
FooDataEnt fooDataEnt = fooDataRepository.findByFooDataId(id);
if (fooDataEnt != null) {
return convertFooDataEntToFooData.apply(fooDataEnt);
}
throw new NotFoundException("Foo not found");
}
}
The FooDataRepository extends Spring's PagingAndSortingRepository.
Katharsis config in application.yaml:
katharsis:
resourcePackage: com.my.package
domainName: http://localhost:8080
pathPrefix: /api/kat
The request and response from PostMan
-- UPDATE 1 --
Apparently the configured value for katharsis.pathPrefix was not correct. Web application's context-root is "/api" and the value of katharsis.pathPrefix should be only "/kat".
My next problem is that a RepositoryNotFoundException is being throw while handling the request, while the Resource class is found already.
I don't see your foo data service implementation anywhere. However, I am 99% sure you're not passing the json api accept type.
Accept: application/vnd.api+json
I solved the riddle by debugging the code and finding out that my Katharsis config was not correct. Katharsis only picked up the resource classes but not the resource repository classes. When I changed the katharsis.resourcePackage to a higher level where the resource repositories resided, the problem got solved and Katharsis picked up all related annotated classes.
Hi I am trying to create a spring mvc application on wildfly 9 with spring data jpa, when I add in the jpa related config and dependencies, it gets NoClassDef Found error. Here's the server log:
Caused by: java.lang.NoClassDefFoundError: org/hibernate/HibernateException
at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.(HibernateJpaVendorAdapter.java:60)
Maven pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>testspringmvc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
<spring.version>4.2.0.RELEASE</spring.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-parent</artifactId>
<version>9.0.1.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
The config class
package com;
//import skipped...
#Configuration
#ComponentScan(basePackages = "com*")
#EnableWebMvc
#EnableJpaRepositories
#EnableTransactionManagement
public class TestAppConfig extends WebMvcConfigurerAdapter {
#Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.freeMarker().cache(false);
}
#Bean
public FreeMarkerConfigurer freeMarkerConfigurer() throws TemplateException, IOException {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPath("/WEB-INF/freemarker/");
return configurer;
}
#Bean
public AbstractPlatformTransactionManager transactionManager() {
return new JpaTransactionManager(entityManagerFactory());
}
#Bean
public EntityManagerFactory entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
bean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); //This is the line the log complaining
bean.setDataSource(dataSource());
final Properties props = new Properties();
props.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
props.setProperty("hibernate.hbm2ddl.auto", "validate");
props.setProperty("hibernate.show_sql", "true");
props.setProperty("hibernate.format_sql", "true");
bean.setJpaProperties(props);
return bean.getObject();
}
#Bean
public DataSource dataSource() {
final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
dsLookup.setResourceRef(true);
DataSource dataSource = dsLookup.getDataSource("java:/PostgresDS");
return dataSource;
}
}
Did i do anything wrong?
For maven, i read somewhere that using jpa should not include hibernate-core but the HibernateException is in there, but include and exclude it gives the same error.
Project ran on wildfly 9 using eclipse and wildfly plugin.
Thank you very much.
You need to put provided scope for jpa 2.1 api, and exclude the same api from hibernate core for it to work.