How to configure Spring facet in IntelliJ IDEA - spring

I'm new to Intellij 14.0 . I was using Netbeans, but my colleagues told me to shift to intellij and so I did.
I need to run the same project that I ran on netbeans in Intellij. The project that I'm working on is made of grails and spring. When I tried to run the project using Intellij this is what I get.
Spring Configuration Check
Unmapped Spring configuration files found.
Please configure/setup Spring facet for modules:
......... (1 file)
And this is the file.
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
<description>Grails application factory bean</description>
<property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
<property name="grailsResourceLoader" ref="grailsResourceLoader" />
</bean>
<bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
<description>A bean that manages Grails plugins</description>
<property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
<property name="application" ref="grailsApplication" />
</bean>
<bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
<constructor-arg>
<ref bean="grailsApplication" />
</constructor-arg>
<property name="pluginManager" ref="pluginManager" />
</bean>
<bean id="grailsResourceLoader" class="org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean" />
<bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
<property name="encoding">
<value>utf-8</value>
</property>
</bean>
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean" />
</beans>
Honestly, I dont have any idea how to fix it. Based on my understanding it is looking for some modules but I could not fix it. I even tried this "Add framework support" . But I couldn't find spring in the list.
Could you help me fix this? Thanks

Go to File/Project Structure/Modules, click the green plus icon, select Spring from the dropdown and select your module in the next dialog.
Then click the green plus in the right pane, click plus and select your Spring configuration files and classes and click OK.
Also take a look at IntelliJ Help for Spring Facet.

Just ran into this issue out of the blue today—my build was working last night, and this morning it stopped working—so I figured I'd post my solution using IntelliJIDE CE 2019.1.
Error Messages (to help people find this answer)
package org.springframework.transaction.annotation does not exist
package org.springframework.boot does not exist
Unknown facet type: 'Spring'
Unknown facet type: 'web'
Solution
Step 0:
Update IntelliJ
Menu: IntelliJIDE > Check for Updates (Mac OSX)
Step 1:
Clean out Maven repo and re-download dependencies to ensure that the sources are not corrupt. This will take 5+min.
$ cd [project_directory]
$ mvn dependency:purge-local-repository
Step 2:
Preform a clean install.
$ mvn clean install
Step 3:
Update IntelliJIDE's Repository Indexes:
Open IntelliJ Settings/Preferences
Build, Execution, Deployment > Build Tools > Maven > Repositories
Select repositories one by one (by clicking on the table row) and click the update button. Specifically, do it for https://repo.mave.apache.org/maven2. The download is ±700mb so it will take a while. (10+min)
Related Questions
getting package org.springframework.transaction.annotation does not exist error while packaging app
package org.springframework.boot does not exist

IntelliJ Ultimate 2018 - the manual way:
Menu File -> Project Structure
Right-click on your module and choose "Add..." -> Spring
Optionally click "fix" if spring is not listed as a dependency
Click the + icon at the top to add your spring configuration .xml file(s)
The automatic way:
Click the body of the popup notification
Click the "Create Default" option

Related

Using PropertyPlaceholderConfigurer to access test resources

In my IntelliJ project, under the project root, there is a config folder.
This is where various .properties files are located.
Within the application, these are made available to Spring in the standard way, using a propertiesConfigurer.xml file:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:config/${name}.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
The reason they are accessed using 'file', is that eventually they may be external to the deployed jar.
This works, both when running the application, and when running unit tests.
I also wish to access files which are only for use when running tests.
I have placed these under:
test
--- resources
-------META-INF
----------spring
-------------config
I have added this line to the list of locations within the same propertiesConfigurer.xml:
<value>classpath*:META-INF/spring/config/${name}.properties</value>
This is not working. No file or resource exception is being thrown, but none of the properties defined in the test file are being resolved within the application.
Within the IntelliJ Project Settings->Modules, src\test\resources is listed as a context root.
Also, on the file system, under:
...\target\test-classes\META-INF\spring\config
the test property files exist.
What is the correct way to access them?
Thanks

NoClassDefinitionError with simple bean configuration

<bean id="xmlItemReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="fragmentRootElementName" value="SomeElement" />
<property name="unmarshaller" ref="jaxb2unmarshaller" />
</bean>
<bean id="jaxb2unmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>org.MappedClass</value>
</list>
</property>
</bean>
I started with multi step job and have issue when packaged as the job module in the spring-xd, I stripped all the other beans from the configuration and finally figured the issue was coming due to the above two beans.
The spring-oxm jar is present in the custom modules lib. I am using spring-xd 1.0.0.RC1.
I don't want to put the jars in to the server lib, all the required libraries should be part of the custom module lib directory.
How to get it working?
If I place the spring-oxm jar in the spring-xd/lib directory the error goes but then I get the other errors too.
I guess the real reason for the NoClassDefError could be the missing dependencies and the error does not indicate the information about the missing dependent class.
Any inputs would be appreciated?
The information provided is not sufficient to conclude anything. However, you could check the second last line of the code block provided above. The closing <property> tag is missing or it's a TYPO while writing the code here.
The module's dependent jars should go in the module's lib/ directory if they are not on the server class path already. Spring XD 1.1 has improved support for module packaging but in 1.0 you need to install the jars manually. Also, I would suggest upgrading to 1.1.0.M2 or 1.0.3.RELEASE at least.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named xxx

Can't test a jpa/maven project. I have the error
"javax.persistence.PersistenceException: No Persistence provider for EntityManager named xxx"
when I run "mvn cleant test" from commandline. I have a Java SE project.
I have the persistence confiuration in 'src/test/resources/META-INF/persistence.xml'. And I also has the same for 'src/main/...'.
I can see the persistence.xml in 'target/classes/META-INF'. Only that is from the main, not from the test as I run the tests. This is not yet the problem, since both should work anyway.
Trying the JPA for the first time, but as I see, the files should be ok (location and content).
The persistence unit names should match also.
I'm using Eclipse (EE) with m2 and other necessary plugins, but running maven from commandline. I see no errors in the project.
// Update
Tried fixing the maven build as I noticed it should have the test classes and resources in 'target/test-classes'.
Changed the command to "mvn clean test-compile test"
Now the resources can be found from the correct place, but I still got the same error.
// update
For clarity here's the full persistence.xml
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="xxx"
transaction-type="RESOURCE_LOCAL">
<provider>my.package.EntityManagerFactoryHelper</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/db" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="yyy" />
<property name="javax.persistence.jdbc.password" value="zzz" />
<property name="eclipselink.ddl-generation" value="DROP_AND_CREATE" />
</properties>
</persistence-unit>
I took the helper example from other posts. Basically it just creates the emf using the 'xxx' persistence unit. Here's the helper class. http://pastebin.com/1GE6uMa1
Try to add < provider>org.hibernate.ejb.HibernatePersistence< /provider> inside tag
The provider has to be:
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
Else the table creation fails, even that there is no errors when creating the tables from the entities.
Spent about 2 days resolving this, since I thought I was pointed the right direction by the given hint and didn't check the provider then.
The provider has to be according to the eclipselink, as you could spot it in the configuration of the 'persistence.xml'.
But I failed to say it explicitly. Didn't know it would matter that much and it even succeeded with the table creation once. Not really sure what I had for the provider then, but it failed subsequently (after changes made to the table).
Probably there should had been other configurations by the provider.

Spring Security fails on WebXmlMappableAttributesRetriever

I have a Spring-Web-App that fails when I try to deploy it to my local tomcat since I've added Spring-security.
I used the securty-web-auth with a preauth filter. The RolesRetriever fails with fallowing Error-Message
class path resource [WEB-INF/web.xml] cannot be opened because it does not exist
But the web.xml exists and worked before the security setup.
<bean id="j2eeMappableRolesRetriever"
class="org.springframework.security.web.authentication.preauth.j2ee.WebXmlMappableAttributesRetriever">
<property name="resourceLoader" ref="webAppContext" />
</bean>
<bean id="webAppContext"
class="org.springframework.web.context.support.GenericWebApplicationContext" />
Has someone and idea, why it fails? It must be within the WebAppContext-Bean but I have no Idea where to set the right path to web.xml

PropertyPlaceholderConfigurer does not find property file on disk

I am trying to move a working spring WAR to OSGI environment (in glassfish 3.1 and blueprint, spring 3.0.5).
The application loads properties file from disk, like this:
<bean id="myProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="${my_conf}/my.properties"/>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
</bean>
I see in debugger that ${my_conf}/my.properties is translated to the existing path (c:\conf\my.properties)
I use the property jms.url defined in my.properties in the next bean declaration
<amq:broker useJmx="false" persistent="false" brokerName="embeddedbroker">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://${jms.url}"/>
<amq:transportConnector uri="vm://embeddedbroker" />
</amq:transportConnectors>
</amq:broker>
And in deployment I get an exception "Could not resolve placeholder ${jms.url}"
Why it fails? Is there another way to load properties from file on disk?
thank you
Since its an OSGI environment, you will need spring-osgi-core jar added to your application. Take a look at this link to configure property-placeholder for OSGI framework.
It isn't a solution, but an explanation of my problem.
The problem is related to this bug in spring 3 and osgi.
I had to open spring logs to debug level to understand it.

Resources